To get IP details through an API in Python, you can use the requests library to send a GET request to an IP lookup API, such as ipapi or ipinfo. Here's an example using ipapi:

import requests

ip = '8.8.8.8'
url = f'https://ipapi.co/{ip}/json/'

response = requests.get(url)
data = response.json()

print(data)

This will send a GET request to the ipapi API with the IP address '8.8.8.8' and return the JSON response containing details about the IP address. You can then access the data using dictionary keys, like so:

print(data['ip'])
print(data['city'])
print(data['region'])
print(data['country_name'])

This will print the IP address, city, region, and country name associated with the IP address.

Python IP Details API: Get IP Information Using ipapi

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

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