Login Register






Thread Rating:
  • 0 Vote(s) - 0 Average


Get your public IP Address + details with Python filter_list
Author
Message
Get your public IP Address + details with Python #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 )

[+] 1 user Likes CoolBro's post
Reply

RE: Get your public IP Address + details with Python #2
I personally wouldn't trust iplist.cc, it's kinda shady.
Except if you don't care about having your public IP on some public/sold lists

[+] 1 user Likes fritz's post
Reply

RE: Get your public IP Address + details with Python #3
Is there any built in module for this?

Reply

RE: Get your public IP Address + details with Python #4
(03-01-2022, 02:51 PM)PhantomIN Wrote: Is there any built in module for this?

If you mean not using a third party module you have to install with pip, yes, you could use urllib.request instead of the requests module.
If you mean without calling on an external service, not that I'm aware of. You can use the socket module to get your internal ip address, but to get external IP the most common method is from getting the response from ipify.org or another ip resolver service endpoint.

Reply

RE: Get your public IP Address + details with Python #5
thanks man really appreciate it.impressedd!

Reply







Users browsing this thread: 2 Guest(s)