Python – Find IP Location

import requests

api_key = "YOUR_API_KEY"
ip_address = input("Enter the IP address: ")

url = f"http://api.ipstack.com/{ip_address}?access_key={api_key}"
response = requests.get(url)
data = response.json()

if "error" in data:
    print("Error:", data["error"]["info"])
else:
    location = {
        "IP": data["ip"],
        "Country": data["country_name"],
        "Region": data["region_name"],
        "City": data["city"],
        "Latitude": data["latitude"],
        "Longitude": data["longitude"]
    }
    print(location)

 

Replace “YOUR_API_KEY” with your actual API key obtained from the ipstack website.