ip2region - is an offline IP address localization library and IP localization data management framework. It supports both IPv4 and IPv6 with query efficiency at the 10-microsecond level. It provides xdb data generation and query client implementations for many mainstream programming languages.
The project itself provides raw data for both IPv4 (data/ipv4_source.txt) and IPv6 (data/ipv6_source.txt), along with corresponding xdb files (data/ip2region_v4.xdb and data/ip2region_v6.xdb) to achieve city-level query localization. The field format is: Country|Province|City|ISP|iso-alpha2-code. Localization information for China is entirely in Chinese, while regional information for non-China areas is entirely in English.
xdb supports hundreds of millions of IP data segment rows. Region information supports full customization. The region information of the built-in data is fixed in the format: Country|Province|City|ISP|iso-alpha2-Code. You can append data for specific business needs to the region, such as: GPS information/International Standard Regional Codes/Zip codes, etc. In other words, you can fully use ip2region to manage your own IP localization data.
The xdb format generation program automatically processes the input raw data, checks and completes the merging of adjacent IP segments, and performs deduplication and compression of identical regional information.
Even for queries based entirely on the xdb file, the single query response time is at the 10-microsecond level. Memory-accelerated queries can be enabled through the following two methods:
vIndexIndex Caching: Uses a fixed512KiBof memory to cache vector index data, reducing one disk IO operation and maintaining average query efficiency within 100 microseconds.- Entire
xdbFile Caching: Loads the entirexdbfile into memory. Memory usage is equal to thexdbfile size. There is no disk IO operation, maintaining 10-microsecond level query efficiency.
xdb provides version-compatible query implementations. A unified API can simultaneously provide queries for both IPv4 and IPv6 data and return unified data.
For API introductions, usage documentation, and test programs, please refer to the README introduction under the corresponding searcher query client. All query binding implementations are as follows:
| Language | Description | IPv4 | IPv6 | Contributors |
|---|---|---|---|---|
| Golang | golang xdb query client | ✅ | ✅ | Lion |
| PHP | php xdb query client | ✅ | ✅ | Lion |
| Java | java xdb query client | ✅ | ✅ | Lion |
| C | POSIX C xdb query client | ✅ | ✅ | Lion |
| Lua_c | lua c extension xdb query client | ✅ | ✅ | Lion |
| Lua | lua xdb query client | ✅ | ✅ | Lion |
| Rust | rust xdb query client | ✅ | ✅ | gongzhengyang |
| Python | python xdb query client | ✅ | ✅ | Lion |
| Javascript | javascript xdb query client | ✅ | ✅ | Lion |
| Csharp | csharp xdb query client | ✅ | ✅ | Alen Lee & ArgoZhang |
| Erlang | erlang xdb query client | ✅ | ❌ | malou |
| Nginx | nginx extension xdb query client | ✅ | ❌ | Wu Jian Ping |
| C++ | C++ xdb query client | ✅ | ✅ | Yunbin Liu |
The following toolchain implementations are contributed by community developers via third-party repositories:
| Language | Description | Contributors |
|---|---|---|
| ip2region-composer | php composer management client | Zou Jingli |
| ip2region-ts | node.js addon management client | Steven Qiang |
| ruby-ip2region | ruby xdb query client implementation | jicheng1014 |
| Ip2regionTool | ip2region data conversion tool | orestonce |
For API introductions, usage documentation, and test programs, please refer to the README documents under the following maker generation programs:
| Language | Description | IPv4 | IPv6 | Contributors |
|---|---|---|---|---|
| Golang | golang xdb generation program | ✅ | ✅ | Lion |
| Java | java xdb generation program | ✅ | ✅ | Lion |
| Python | python xdb generation program | ✅ | ❌ | leolin49 |
| Csharp | csharp xdb generation program | ✅ | ❌ | Alan Lee |
| Rust | rust xdb generation program | ✅ | ✅ | KevinWang & gongzhengyang |
| C++ | C++ xdb generation program | ✅ | ✅ | Yunbin Liu |
The core of the ip2region project lies in researching the design and implementation of IP data storage and fast querying. The raw data ./data/ipv4_source.txt and ./data/ipv6_source.txt included in the project are updated irregularly. For scenarios with high requirements for data accuracy and update frequency, it is recommended to purchase commercial offline data from the Ip2Region Community or third-party vendors. You can try to update the data yourself using the following methods:
You can modify the data yourself based on the raw IP data provided by ip2region in ./data/ipv4_source.txt and ./data/ipv6_source.txt using the editing tools provided by ip2region. Currently, the data sources include:
- Data provided by the ip2region community (please refer to the official account at the bottom for community notifications)
- Project Issues tagged with
[Data_Updates] - Other custom data: e.g., data provided by customers, data obtained through GPS and WIFI positioning, or legal and compliant data from other platforms.
For instructions on using the raw IP data editing tools, please refer to the README documents under the following maker generation programs:
| Language | Description | IPv4 | IPv6 | Contributors |
|---|---|---|---|---|
| Golang | golang IP raw data editor | ✅ | ✅ | Lion |
| Java | java IP raw data editor | ✅ | ❌ | Lion |
| C++ | C++ IP raw data editor | ✅ | ✅ | Yunbin Liu |
If you want to update data via your own API or data source, you can refer to the update algorithm based on the "Detection Algorithm" shared in the following videos to write your own update program:
The Ip2Region official community was officially launched on 2025/06/12. On one hand, it provides stable commercial offline data services. On the other hand, it facilitates the strengthening of the IP toolchain and data services outside the core code, such as usage documentation, query testing, and data correction. For more information and services regarding the community, please visit the Ip2Region Official Community.
- xdb Data Structure Analysis: "ip2region xdb - Data Structure Description"
- xdb Query Process Analysis: "ip2region xdb - Query Process Description"
- xdb Generation Process Analysis: "ip2region xdb - Generation Process Description"
- xdb File Generation Tutorial: "ip2region xdb - File Generation Tutorial"
- xdb Concurrent Safety Query: "ip2region xdb - Concurrent Safety Query"
- xdb Data Update Method: "ip2region Data Update and Use of xdb Data Editor"
- WeChat Official Account - lionsoul-org, the author's active technical sharing channel
- Ip2Region Official Community