python免费api查询ip地址的最详细的地理位置
您可以使用以下代码使用免费的API查询IP地址的最详细的地理位置:
import requests
ip_address = '8.8.8.8' # 要查询的IP地址
url = f'http://ip-api.com/json/{ip_address}' # API请求URL
response = requests.get(url)
if response.status_code == 200: # 如果请求成功
data = response.json()
if data['status'] == 'success': # 如果查询成功
print('IP地址:', data['query'])
print('国家:', data['country'])
print('省份:', data['region'])
print('城市:', data['city'])
print('经度:', data['lon'])
print('纬度:', data['lat'])
else:
print('查询失败!')
else:
print('请求失败!')
该代码使用了ip-api.com提供的免费API。查询结果包括IP地址、国家、省份、城市、经度和纬度。请注意,使用免费API有查询次数限制和请求速度限制。如果需要更多的查询次数和更快的响应速度,请考虑使用付费的IP地址查询服务
原文地址: https://www.cveoy.top/t/topic/fsrn 著作权归作者所有。请勿转载和采集!