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.

Official API Clients

Language or FrameworkPackage RepositoryDocumentationVersion Control
.NET (C#)NuGetGitHub PagesGitHub
JavaMaven Central RepositoryGitHub PagesGitHub
JavaScript (browser)API Docs
Node.jsNPMGitHub PagesGitHub
Perl (deprecated)CPANMetaCPANGitHub
PHPPackagistGitHub PagesGitHub
PythonPyPIRead the DocsGitHub
RubyRubyGemsRubyDocGitHub

Unofficial API Clients

Use at your own risk.

MaxMind does not offer support for these integrations. Please contact the integrator for assistance.

Language or SoftwareAPI NamePackage RepositoryDocumentationVersion Control
C++GeoLite2++Usage
ClojuremaximatorClojarsREADMEGitHub
Common LispCL-MAXMINDDBREADMEGitHub
CrystalGeoIP2.cr (C extension)READMEGitHub
CrystalMaxMindDB.crREADMEGitHub
DdmaxminddbDUBDUBGitHub
DelphiMMDB ReaderREADME.mdGitHub
ElixirGeolixHexREADMEGitHub
ErlangegoREADMEGitHub
Erlanggeodata2READMEGitHub
ErlanglocusHexHexDocsGitHub
Gooschwald/geoip2-golangpkg.go.devGitHub
GoIncSW/geoip2pkg.go.devGitHub
Haskellgeoip2HackageREADMEGitHub
LuammdbluaREADMEGitHub
Lua (C extension)lua-maxminddbGitHub
Lua (C extension)lua-resty-maxminddbREADMEGitHub
OCamlocaml-maxminddbOPAMREADMEGitHub
RrgeolocateCRANREADMEGitHub
RacketgeoipRacket DocumentationGitHub
RakuGeoIP2READMEGitHub
RustmaxminddbCargoAPI docsGitHub
Scalamaxmind-geoip2-scalaREADMEGitHub
Swift (C extension)MMDB-SwiftMMDB-SwiftCocoaPodsGitHub

Command Line (mmdbinspect)

You can use the mmdbinspect tool (in beta), a command line interface built with Go, to look up one or more IPs from one or more MMDB databases and receive output in a parsable JSON format.

This page was last updated on June 17, 2021.