Show region-specific content or language to users based on their IP location without calling external APIs.
Enforce geo-restrictions or block traffic from specific countries directly in your application.
Log and analyze where your traffic originates for security and analytics without external dependencies.
ip2region is an offline library that translates an IP address into geographic and network information, specifically the country, province, city, and internet service provider, without making any network requests. Most IP-to-location lookups call a remote API, which adds latency, costs money, and stops working if you go offline. ip2region bundles all the lookup data in a compact binary file format called xdb that you ship with your application. Lookups against the xdb file take around 10 microseconds (incredibly fast, that's about ten millionths of a second). You can optionally load part or all of the file into memory to make it even faster. The library supports both IPv4 and IPv6 addresses and exposes a consistent API across many programming languages, including Go, Java, Python, JavaScript, Rust, C, C++, PHP, C#, Lua, Erlang, and even an Nginx extension. You would use ip2region when you need to geolocate users inside your own infrastructure, for example to show region-specific content, enforce geo-restrictions, or log where traffic comes from, without depending on an external service. The core project is written in Java, though client libraries are available in over a dozen languages. The bundled IP data is updated periodically; teams with high accuracy requirements can integrate commercial data from the ip2region community.
Generated 2026-05-18 · Model: sonnet-4-6 · Verify against the repo before relying on details.