[Python] Is there a free python API for locating IPs apart from ip-api?

Discussão em 'Python' iniciado por Stack, Abril 28, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to make a python IP locator, which currently relies on this function:

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


    Is there an alternative method of doing this that is more accurate, or can provide an exact street-level adress while still being free?

    Continue reading...

Compartilhe esta Página