Get geographic location through IP address, support IPv4 and IPv6. Combine IP address library and online API.
Project description
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: ipregion
How to use 使用方法
Install 安装:
pip install ip-region
Use 使用:
from ipregion import IP2Region
ip2region = IP2Region()
region = ip2region.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 ipregion import IP2Region
import json
app = Flask(__name__)
@app.route("/ip/<ip>")
def get_ip(ip=None):
ip2region = IP2Region()
region = ip2region.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/*
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ip_region-0.0.3.tar.gz.
File metadata
- Download URL: ip_region-0.0.3.tar.gz
- Upload date:
- Size: 4.3 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
542c5cdf51b08bab819a0097c48b68a61a42119237f966b325411cdfbdf4269a
|
|
| MD5 |
2d5f3138218d85bee3697b4053f7bf61
|
|
| BLAKE2b-256 |
7eea1e47e0bbbab8858a2127ea93de023fb65aaf73fbdbd8ddc4f42001c332ba
|
File details
Details for the file ip_region-0.0.3-py3-none-any.whl.
File metadata
- Download URL: ip_region-0.0.3-py3-none-any.whl
- Upload date:
- Size: 4.3 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
50304bc2b9c2edec659d80afcad5922fdbbe847120369ca8d84d77178f572318
|
|
| MD5 |
1b27e8a4c4067fab68807608cff54fe5
|
|
| BLAKE2b-256 |
6fa19368886b4c06b746c4f3fb9af42e0985b72e49a209a5f2d13150f7a3d7ce
|