Sinisterly
Get your public IP Address + details with Python - Printable Version

+- Sinisterly (https://sinister.ly)
+-- Forum: Coding (https://sinister.ly/Forum-Coding)
+--- Forum: Python (https://sinister.ly/Forum-Python)
+--- Thread: Get your public IP Address + details with Python (/Thread-Get-your-public-IP-Address-details-with-Python)



Get your public IP Address + details with Python - CoolBro - 01-11-2022

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}')



RE: Get your public IP Address + details with Python - fritz - 01-11-2022

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


RE: Get your public IP Address + details with Python - PhantomIN - 03-01-2022

Is there any built in module for this?


RE: Get your public IP Address + details with Python - hexexom - 03-08-2022

(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.


RE: Get your public IP Address + details with Python - anime32 - 03-20-2022

thanks man really appreciate it.impressedd!