Skip to main content

IP address location 通过IP地址获取地理位置

简介

Get geographic location through IP address, support IPv4 and IPv6. Combine IP address library and online API. The local IP address library comes from the project lionsoul2014/ip2region, and the online API comes from ip-api and ip.sb.

通过IP地址获取地理位置,支持IPv4和IPv6。结合了IP地址库和在线API。本地的IP地址库来自项目lionsoul2014/ip2region,在线API来自ip-api、ip.sb。

Pypi: LocateIP

How to use 使用方法

Install 安装:

pip install LocateIP

Use 使用:

from LocateIP import LocateIP
locateIP = LocateIP()
region = locateIP.search('8.8.8.8')

Use in Flask 结合Flask使用

Example file 示例文件: example1_flask.py

View it on github 请在github上查看 example1_flask.py

insstall Flask 安装Flask:

pip install flask

run 运行:

python example1_flask.py

visit 访问本地测试路径:

http://127.0.0.1:5000/ip/<search ip>

API:

# 获取IP对应位置
GET http://127.0.0.1:5000/ip/8.8.8.8
# 获取IPv6对应位置
GET http://127.0.0.1:5000/ip/2406:da14:2e4:8900:b5fc:b35a:34d0:93f6
### 获取IP对应位置, 使用jsonp, callbackFunction可以自定义
GET http://127.0.0.1:5000/ip/8.8.8.8?callback=callbackFunction

Example code 示例代码:

from flask import Flask, jsonify, request
from LocateIP import LocateIP
import json
app = Flask(__name__)
@app.route("/ip/<ip>")
def get_ip(ip=None):
    locateIP = LocateIP()
    region = locateIP.search(ip)
    # json
    if not request.args.get('callback') or request.args.get('callback').strip() == '':
        return jsonify(region)
    # jsonp
    else:
        return request.args.get('callback') + "(" + json.dumps(region) + ")"
if __name__ == "__main__":
    app.run(debug=True)

LICENSE

Apache-2.0 License

Source code

https://github.com/jeeaay/py-ip-location

Upload to pypi

install twine and build

pip install twine build

build

python -m build

upload

twine upload dist/*

Metadata

Release files for LocateIP 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for LocateIP 1.0.0
File Size Uploaded Provenance Actions
locateip-1.0.0.tar.gz 4.3 MB Without provenance Details for locateip-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for LocateIP 1.0.0
File Interpreter ABI Platform Actions
LocateIP-1.0.0-py3-none-any.whl Python 3 none any Details for LocateIP-1.0.0-py3-none-any.whl

Total release size: 8.7 MB

Release files / locateip-1.0.0.tar.gz

Download URL locateip-1.0.0.tar.gz
Size 4.3 MB
Tags Source
SHA-256 checksum
How to use checksums
765e4108c51cb90e5e10b4617ed6649f43aac7ff0b7db964ec2caf70e442791e
BLAKE2b-256 checksum
How to use checksums
fcc9d5f8877bcb2d7e5db477a3f7c3d700e853bc8bf1b40c5792ec48b1aa63cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.8

Release files / LocateIP-1.0.0-py3-none-any.whl

Download URL LocateIP-1.0.0-py3-none-any.whl
Size 4.3 MB
Tags Python 3
SHA-256 checksum
How to use checksums
82fedd5d8b9a9587d5d68956563a7a0a03d0f7944f2e028d2a1372c29c289f3f
BLAKE2b-256 checksum
How to use checksums
ae732f932c8bda96d5adde93eefa040c7967701a9c5a5b1641ea332feff20609
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.8

Security for LocateIP 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page