ip_geolocate library

IPv4 geolocation using the free geolite2-city-json dataset (MaxMind GeoLite2-City), served as static JSON from a CDN.

final loc = await geolocate('8.8.8.8');
print(loc?.country); // US

Classes

GeoLocation
A location resolved for an IPv4 address. Every field may be null — the dataset often knows only some of them (e.g. a country but no city).

Functions

decodeSixteen(Map<String, dynamic> file, int c, int d) GeoLocation?
Decodes a single /16 file body (data/<A>/<B>.json) for third and fourth octets c and d. Pure (no I/O) — useful for offline decoding and tests.
geolocate(String ip) Future<GeoLocation?>
Resolves ip (a dotted-quad IPv4 string like '8.8.8.8') to a GeoLocation, or null if the dataset has no data for it.
parseIpv4(String ip) List<int>
Parses a dotted-quad IPv4 string into four octets (each 0–255).