Skip to main content

GeoIP.Network 的官方 python 接口

项目描述

GeoIP.Network Python 库

发布徽章 管道徽章

GeoIP.Network 的官方 python 接口

下面的示例代码截图

在世界任何地方即时本地化 IP 地址。

通过使用 GeoIP.Network 实时发现客户的位置,改善客户体验并优化营销。

我们的 API 每天最多可免费用于 10,000 个请求(比大多数商业项目每月在其付费套餐中提供的要多) - 如果您以每月一杯咖啡的费用赞助该项目,则可以无限制使用。立即发现 ISP、国家和位置等详细信息。GeoIP.Network 是一个非营利(和开源)项目,旨在为所有人免费提供可靠和准确的 IP 本地化数据。基于在世界领先大学完成的研究,我们使用来自 Internet 路由注册表 (IRR)、实时 BGP 流和随机渐进延迟测量算法的信息的混合,以提供最新和最准确的数据。

TLDR;我们使用科学和公共数据,并免费提供准确的 GeoIP 数据。

使用情况(免费 < 10000 个请求/天):

注意:以下 IP 地址是文档地址。因此,您需要将它们替换为有效的公共 IP 地址才能使这些示例正常工作。

import geoip_network
# Single IP
result = geoip_network.lookup_ip("198.51.100.1")
print(result.to_dict())
# {"allocated_cc": "--", "as-name": "Documentation ASN", "asn": "AS64496", "cidr": "198.51.100.0/24", "geo": {"geometry": {"coordinates": [-112.404207, 45.73643438], "type": "Point"}, "properties": {"radius": 0.0}, "type": "Feature"}, "rir": "IANA", "timestamp": 1643422555},

# IP Range (CIDR)
result = geoip_network.lookup_cidr("198.51.100.0/24")
print(result.to_dict())
# {"allocated_cc": "--", "as-name": "Documentation ASN", "asn": "AS64496", "cidr": "198.51.100.0/24", "geo": {"geometry": {"coordinates": [-112.404207, 45.73643438], "type": "Point"}, "properties": {"radius": 0.0}, "type": "Feature"}, "rir": "IANA", "timestamp": 1643422555},

# Bulk lookup
for result in geoip_network.lookup_bulk(["2001:db8::/48", "198.51.100.1", "0.0.0.0/24"]):
    print(result.to_dict())
# {"allocated_cc": "--", "as-name": "Documentation ASN", "asn": "AS64496", "cidr": "2001:db8::/32", "geo": {"geometry": {"coordinates": [16.72425629, 62.88018421], "type": "Point"}, "properties": {"radius": 0.0}, "type": "Feature"}, "rir": "IANA", "timestamp": 1634593342},
# {"allocated_cc": "--", "as-name": "Documentation ASN", "asn": "AS64496", "cidr": "198.51.100.0/24", "geo": {"geometry": {"coordinates": [-112.404207, 45.73643438], "type": "Point"}, "properties": {"radius": 0.0}, "type": "Feature"}, "rir": "IANA", "timestamp": 1643422555},
# {"error": "no covering prefix found"}

用途(赞助商):

注意:以下 IP 地址是文档地址。因此,您需要将它们替换为有效的公共 IP 地址才能使这些示例正常工作。

import geoip_network
# Login

geoip = geoip_network.GeoIP("api_username", "api_password")
# Single IP

result = geoip.lookup_ip("198.51.100.1")
print(result.to_dict())
# {"allocated_cc": "--", "as-name": "Documentation ASN", "asn": "AS64496", "cidr": "198.51.100.0/24", "geo": {"geometry": {"coordinates": [-112.404207, 45.73643438], "type": "Point"}, "properties": {"radius": 0.0}, "type": "Feature"}, "rir": "IANA", "timestamp": 1643422555},

# IP Range (CIDR)
result = geoip.lookup_cidr("198.51.100.0/24")
print(result.to_dict())
# {"allocated_cc": "--", "as-name": "Documentation ASN", "asn": "AS64496", "cidr": "198.51.100.0/24", "geo": {"geometry": {"coordinates": [-112.404207, 45.73643438], "type": "Point"}, "properties": {"radius": 0.0}, "type": "Feature"}, "rir": "IANA", "timestamp": 1643422555},

# Bulk lookup
for result in geoip.lookup_bulk(["2001:db8::/48", "198.51.100.1", "0.0.0.0/24"]):
    print(result.to_dict())
# {"allocated_cc": "--", "as-name": "Documentation ASN", "asn": "AS64496", "cidr": "2001:db8::/32", "geo": {"geometry": {"coordinates": [16.72425629, 62.88018421], "type": "Point"}, "properties": {"radius": 0.0}, "type": "Feature"}, "rir": "IANA", "timestamp": 1634593342},
# {"allocated_cc": "--", "as-name": "Documentation ASN", "asn": "AS64496", "cidr": "198.51.100.0/24", "geo": {"geometry": {"coordinates": [-112.404207, 45.73643438], "type": "Point"}, "properties": {"radius": 0.0}, "type": "Feature"}, "rir": "IANA", "timestamp": 1643422555},
# {"error": "no covering prefix found"}

或者

注意:以下 IP 地址是文档地址。因此,您需要将它们替换为有效的公共 IP 地址才能使这些示例正常工作。

import geoip_network
# Single IP

result = geoip_network.lookup_ip("198.51.100.1", auth="<bearer_token>")
print(result.to_dict())
# {"allocated_cc": "--", "as-name": "Documentation ASN", "asn": "AS64496", "cidr": "198.51.100.0/24", "geo": {"geometry": {"coordinates": [-112.404207, 45.73643438], "type": "Point"}, "properties": {"radius": 0.0}, "type": "Feature"}, "rir": "IANA", "timestamp": 1643422555},

# IP Range (CIDR)
result = geoip_network.lookup_cidr("198.51.100.0/24", auth="<bearer_token>")
print(result.to_dict())
# {"allocated_cc": "--", "as-name": "Documentation ASN", "asn": "AS64496", "cidr": "198.51.100.0/24", "geo": {"geometry": {"coordinates": [-112.404207, 45.73643438], "type": "Point"}, "properties": {"radius": 0.0}, "type": "Feature"}, "rir": "IANA", "timestamp": 1643422555},

# Bulk lookup
for result in geoip_network.lookup_bulk(["2001:db8::/48", "198.51.100.1", "0.0.0.0/24"], auth="<bearer_token>"):
    print(result.to_dict())
# {"allocated_cc": "--", "as-name": "Documentation ASN", "asn": "AS64496", "cidr": "2001:db8::/32", "geo": {"geometry": {"coordinates": [16.72425629, 62.88018421], "type": "Point"}, "properties": {"radius": 0.0}, "type": "Feature"}, "rir": "IANA", "timestamp": 1634593342},
# {"allocated_cc": "--", "as-name": "Documentation ASN", "asn": "AS64496", "cidr": "198.51.100.0/24", "geo": {"geometry": {"coordinates": [-112.404207, 45.73643438], "type": "Point"}, "properties": {"radius": 0.0}, "type": "Feature"}, "rir": "IANA", "timestamp": 1643422555},
# {"error": "no covering prefix found"}

安装(来自 pip):

pip install geoip_network

安装(来自源):

git clone https://gitlab.com/geoip.network/python-library
poetry install

下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

GeoIP-Network-0.1.3.tar.gz (6.0 kB 查看哈希

已上传 source

内置分布

GeoIP_Network-0.1.3-py3-none-any.whl (6.3 kB 查看哈希

已上传 py3