Geolocate an IP address using Web Services
Geolocating an IP address using GeoIP2 or GeoLite2 web services consists of configuring a web service client, creating a request, and handling the response.
Implementation
MaxMind offers and highly recommends using official client libraries to access our geolocation services. If you cannot or do not wish to use our client libraries, please review our GeoIP2 API Documentation page for details on our REST API.
1. Install the GeoIP2 client library
We have a collection of officially supported libraries for you to interact with the GeoIP2 and GeoLite2 APIs:
2. Create and configure a GeoIP2 client object
To interact with our API, you need to create a new client object. For this you will need your MaxMind account ID and license key. Our clients also allow you to interact with our GeoLite2 API, but this requires additional configuration as demonstrated below:
3. Query the desired geolocation service
GeoIP2 offers 3 services: Insights, City Plus, and Country. GeoLite2 offers 2 services: City and Country. Each client library has an appropriately named method for accessing the desired geolocation service.
Client APIs
You can find a complete list of official and third-party client APIs on the web services documentation page.
Command Line (curl) Examples
The web service may be accessed using curl
, a simple command-line HTTP client.
The -u
flag is used to pass the
HTTP basic authentication header
that provides the web service with your credentials.
For the following examples, replace {account_id}
and {license_key}
(including the brackets) with your
account ID and license key, and
replace {ip_address}
with the IP address you wish to look up.
This page was last updated on September 12, 2024.