There are several APIs available that can provide IP details without requiring an API key. One such API is ipinfo.io.

You can use the requests library in Python to make a GET request to the ipinfo.io API endpoint and retrieve the IP details. Here's an example code snippet:

import requests

ip = '8.8.8.8'  # Replace with the IP address you want to get details for

url = f'https://ipinfo.io/{ip}/json'
response = requests.get(url)

if response.status_code == 200:
    data = response.json()
    print(f'IP address: {data['ip']}')
    print(f'Hostname: {data['hostname']}')
    print(f'City: {data['city']}')
    print(f'Region: {data['region']}')
    print(f'Country: {data['country']}')
    print(f'Postal code: {data['postal']}')
    print(f'Latitude: {data['loc'].split(",")[0]}')
    print(f'Longitude: {data['loc'].split(",")[1]}')
else:
    print(f'Request failed with status code {response.status_code}')

This code retrieves the IP details for the IP address '8.8.8.8' using the ipinfo.io API and prints out the details. You can replace the IP address with any other IP address you want to get details for.

Python: Get IP Details Without API Keys using ipinfo.io

原文地址: https://www.cveoy.top/t/topic/mz1M 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录