如何查询一个IP地址的具体归属地信息?
- 内容介绍
- 文章标签
- 相关推荐
本文共计146个文字,预计阅读时间需要1分钟。
免费版,每月限制只能获取3,000次。代码如下:
pythonimport requests
def get_ip(): response=requests.get('https://api64.ipify.org?format=json').json() return response['ip']
def get_location(): ip_address=get_ip() response=requests.get(f'https://ipinfo.io/{ip_address}/geo') return response.json()
免费版,每个月限制只能获取30000
def get_ip():
response = requests.get('api64.ipify.org?format=json').json()
return response["ip"]
def get_location():
ip_address = get_ip()
response = requests.get('ipapi.co/{}/json/'.format(ip_address)).json()
location_data = {
"ip": ip_address,
"city": response.get("city"),
"region": response.get("region"),
"country": response.get("country_name")
}
return location_data
print(get_location())
本文共计146个文字,预计阅读时间需要1分钟。
免费版,每月限制只能获取3,000次。代码如下:
pythonimport requests
def get_ip(): response=requests.get('https://api64.ipify.org?format=json').json() return response['ip']
def get_location(): ip_address=get_ip() response=requests.get(f'https://ipinfo.io/{ip_address}/geo') return response.json()
免费版,每个月限制只能获取30000
def get_ip():
response = requests.get('api64.ipify.org?format=json').json()
return response["ip"]
def get_location():
ip_address = get_ip()
response = requests.get('ipapi.co/{}/json/'.format(ip_address)).json()
location_data = {
"ip": ip_address,
"city": response.get("city"),
"region": response.get("region"),
"country": response.get("country_name")
}
return location_data
print(get_location())

