Get your public IP Address + details with Python 01-11-2022, 11:50 AM
#1
Complete code to get your public/external ip address and its details.
Code:
# This code requires the "requests" module. You can install it using pip: pip install requests
from requests import get
import json
response = get('https://iplist.cc/api/')
# Convert the API response into a Python dictionary
json_data = json.loads(response.text)
# Access each property of the JSON
ip = json_data['ip']
registry = json_data['registry']
countrycode = json_data['countrycode']
countryname = json_data['countryname']
asn_code = json_data['asn']['code']
asn_name = json_data['asn']['name']
asn_route = json_data['asn']['route']
asn_start = json_data['asn']['start']
asn_end = json_data['asn']['end']
asn_count = json_data['asn']['count']
city = json_data['city']
spam = json_data['spam']
tor = json_data['tor']
# Print each property
print(f'IP: {ip}')
print(f'Registry: {registry}')
print(f'Country Code: {countrycode}')
print(f'Country Name: {countryname}')
print(f'ASN Code: {asn_code}')
print(f'ASN Name: {asn_name}')
print(f'ASN Route: {asn_route}')
print(f'ASN Start: {asn_start}')
print(f'ASN End: {asn_end}')
print(f'ASN Count: {asn_count}')
print(f'City: {city}')
print(f'Spam: {spam}')
print(f'Tor: {tor}')
(This post was last modified: 12-05-2023, 10:33 AM by CoolBro.
Edit Reason: New version of the code
)