Python: Get IP Details Using ipinfo.io API (No Key Required)
There are several APIs available that provide IP details without requiring any API key. One such API is ipinfo.io. Here is an example Python code to retrieve IP details using ipinfo.io:
import requests
ip_address = '8.8.8.8' # replace with the IP address you want to lookup
response = requests.get(f'https://ipinfo.io/{ip_address}/json')
data = response.json()
print(f'IP Address: {data['ip']}')
print(f'City: {data['city']}')
print(f'Region: {data['region']}')
print(f'Country: {data['country']}')
print(f'Latitude: {data['loc'].split(',')[0]}')
print(f'Longitude: {data['loc'].split(',')[1]}')
This code retrieves the IP details for the IP address '8.8.8.8' using the ipinfo.io API and prints the IP address, city, region, country, latitude, and longitude. Note that ipinfo.io limits the number of requests you can make per day for free, so if you need to make a large number of requests, you may need to sign up for a paid plan.
原文地址: https://www.cveoy.top/t/topic/mz1I 著作权归作者所有。请勿转载和采集!