lionsoul2014 / ip2region
git clone https://github.com/lionsoul2014/ip2region.git
v3.18.0 · 1mo ago
🔥 on GitHub Trending today
Offline IP-to-region lookup library and data management framework supporting IPv4 and IPv6 with xdb query clients.
Why you might care
Resolves IPs to country, province, city, ISP and ISO code locally with no network calls, at roughly 10-microsecond query time when the xdb file is cached in memory. Ships ready-made IPv4 and IPv6 data and lets you append custom fields like GPS or zip codes to build your own IP location database.
+6
stars, 24h · #2,146
+88
stars, 7 days · #1,453
+~180
stars, 30 days · #2,765
20k
★ total · +0% this week
3.1k
forks · 8 open issues
Star history (as recorded here)
LanguageGo
License—
Created2015-11-02 (10y ago)
Last push4d ago
Watchers439
OwnerUser
Seen on GitHub Trending
- 2026-10-22 — #14 weekly in go · +65 ★
- 2026-10-21 — #9 weekly in go · +71 ★
- 2026-10-20 — #9 weekly in go · +88 ★
GitHub topics
ip-addressip-address-databaseip-address-locationip-locationip-lookupipv4-addressipv4-lookupipv4-supportipv6-addressipv6-lookupipv6-supportxdb-enginexdb-ipv4xdb-ipv6
Links
- GitHub: github.com/lionsoul2014/ip2region
- Homepage: https://ip2region.net
- Releases · Issues · Hacker News mentions
README excerpt
:globe_with_meridians: 中文简体 | English # ip2region 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. # Features ### 1. Offline Localization Library 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. ### 2. Data Management Framework `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. ### 3. Data Deduplication and Compression 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. ### 4. High-Speed Query Response 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: 1. `vIndex` Index Caching: Uses a fixed `512KiB` of memory to cache vector index data, reducing one disk IO operation and maintaining average query efficiency within 100 microseconds. 2. Entire `xdb` File Caching: Loads the entire `xdb` file into memory. Memory usage is equal to the `xdb` file size. There is no disk IO operation, maintaining 10-microsecond level query efficiency. ### 5. Unified Query Interface `xdb` provides version-compatible query implementations. A unified API can simultaneously provide queries for both IPv4 and IPv6 data and return unified data. # `xdb` Query 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 Support | IPv6 Support | | --- | --- | --- | --- | | Golang | golang query client | :white_check_mark: | :white_check_mark: | | PHP | php query client | :white_check_mark: | :white_check_mark: | | Java | java query client | :white_check_mark: | :white_check_mark: | | C | C[std=c99] query client | :white_check_mark: | :white_check_mark: | | Lua_c | lua c extension query client
Blurb generated by claude-haiku-5-5 1d ago. Star deltas marked ~ are extrapolated from partial history.