Skip to main content

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-apiip.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/*

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

locateip-1.0.0.tar.gz (4.3 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

LocateIP-1.0.0-py3-none-any.whl (4.3 MB view details)

Uploaded Python 3

File details

Details for the file locateip-1.0.0.tar.gz.

File metadata

  • Download URL: locateip-1.0.0.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

Hashes for locateip-1.0.0.tar.gz
Algorithm Hash digest
SHA256 765e4108c51cb90e5e10b4617ed6649f43aac7ff0b7db964ec2caf70e442791e
MD5 5b3beba4d60b4777acc6d4c8f722ca53
BLAKE2b-256 fcc9d5f8877bcb2d7e5db477a3f7c3d700e853bc8bf1b40c5792ec48b1aa63cf

See more details on using hashes here.

File details

Details for the file LocateIP-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: LocateIP-1.0.0-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

Hashes for LocateIP-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 82fedd5d8b9a9587d5d68956563a7a0a03d0f7944f2e028d2a1372c29c289f3f
MD5 2809cb75024935feb3de1627efe47874
BLAKE2b-256 ae732f932c8bda96d5adde93eefa040c7967701a9c5a5b1641ea332feff20609

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page