Geolocate an IP address using Databases

Geolocating an IP address using GeoIP2 and GeoLite2 databases consists of configuring a database reader and querying the database.

Implementation

MaxMind offers and highly recommends using official client libraries to query our databases.

1. Install the GeoIP2 client library

We have a collection of officially supported libraries for you to query with the GeoIP2 and GeoLite2 databases:

2. Configure a GeoIP2 database reader to query the database

Configuring the database reader requires the database file to be accessible on the filesystem. After configuring the database reader, you can then query the database by calling the method corresponding to the database type (e.g. city or country) and passing it the IP address you want to look up.

If the lookup succeeds, the method call will return a model class/object for the database method you called. This model in turn contains multiple record classes/objects, each of which represents part of the data for the record.

If the request fails, the reader class will throw an exception or return an error depending on the library.

For more details on database methods, errors, and exceptions, see the client API documentation below.

APIs and Third-Party Integrations

You can find a complete list of official and unofficial client APIs, and third-party integrations on the database documentation page.

This page was last updated on September 12, 2024.