How to improve ip-api locator [closed]Python

Python-Programme
Anonymous
 How to improve ip-api locator [closed]

Post by Anonymous »

Ich versuche, einen Python -IP -Locator zu erstellen, der derzeit auf dieser Funktion beruht: < /p>

Code: Select all

def get_location(ip_address="", show_duplicates=True):
url = f"http://ip-api.com/json/{ip_address}"
try:
response = requests.get(url, timeout=5)
data = response.json()

if data["status"] == "success":
loc_key = (data['city'], data['regionName'], data['country'])

if show_duplicates or loc_key not in seen_locations:
print("\n=== Location Info ===")
print(f"IP Address: {data['query']}")
print(f"City: {data['city']}")
print(f"Region: {data['regionName']}")
print(f"Country: {data['country']}")
print(f"ZIP: {data['zip']}")
print(f"ISP: {data['isp']}")
print(f"Latitude: {data['lat']}")
print(f"Longitude: {data['lon']}")
print(f"Map: https://www.google.com/maps?q={data['lat']},{data['lon']}\n")

seen_locations.add(loc_key)
else:
print(f"{ip_address} - Duplicate location, skipped.")
else:
print(f"{ip_address} - No data.")
except Exception as e:
print(f"Error checking {ip_address}: {e}")
Gibt es eine alternative Methode, um dies mit IP-API zu tun, das spezifischer ist, oder ist dies der optimale Code?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post