Source Code IP Information Script: Displaying and Retrieving Data with Python

Currently reading:
 Source Code IP Information Script: Displaying and Retrieving Data with Python

1ultrapower

Member
LV
1
Joined
Dec 28, 2023
Threads
10
Likes
5
Awards
5
Credits
4,814©
Cash
0$
This script allows you to:

  • Display information about your IP address.
  • Enter an IP address and obtain its information, for example:
    • IP: YOUR IP
    • City: Winston-Salem
    • Region: North Carolina
    • Country: US
    • Location: 36.0999, -80.2442
    • Organization: AS81 MCNC
    • Postal Code: 27111
    • Timezone: America/New_York
This script uses the API from 'The trusted source for IP address data,' a leading IP data provider.

Prerequisites:

  • requests: pip install requests

import requests
import socket
import os



def my_info_ip():
try:
response = requests.get(f"https://ipinfo.io/")
if response.status_code == 200:
data = response.json()
for key, value in data.items():
print(f"{key}: {value}")
else:
print("La requête à l'API a échoué.",response)
except Exception as e:
print(f"Une erreur s'est produite : {str(e)}")


def get_ip_info(ip_address):
try:
os.system('cls')
response = requests.get(f"https://ipinfo.io/{ip_address}/json")
if response.status_code == 200:
data = response.json()
for key, value in data.items():
print(f"{key}: {value}")
else:
print("La requête à l'API a échoué.")
except Exception as e:
print(f"Une erreur s'est produite : {str(e)}")


os.system('cls')


print("--- MY INFOS ---")
my_info_ip()
print("----------------")

ip_address = input("Entrez une adresse IP : ")
get_ip_info(ip_address)
 
  • Like
Reactions: fognayerku

Create an account or login to comment

You must be a member in order to leave a comment

Create account

Create an account on our community. It's easy!

Log in

Already have an account? Log in here.

Tips

Similar threads

Top Bottom