nadzoring.network_base.geolocation_ip module

Geographic IP lookup via ip-api.com.

nadzoring.network_base.geolocation_ip.geo_ip(ip: str) dict[str, str][source]

Retrieve geographic information for a given public IP address.

Queries the ip-api.com JSON API and returns a flat dictionary with location data. Returns an empty dict on any network or parse error.

Parameters:

ip – IPv4 or IPv6 address to geolocate.

Returns:

Dictionary with string keys lat, lon, country, and city when the lookup succeeds, or an empty dict on failure.

Examples

>>> result = geo_ip("8.8.8.8")
>>> "lat" in result and "lon" in result
True