ip2region - is an offline IP address location library and IP location data management framework. It has a query efficiency of 10 microseconds and provides xdb
data generation and query client implementation for many mainstream programming languages.
xdb
supports hundreds of millions of IP data segment rows. The default region information has a fixed format:国家|区域|省份|城市|ISP
. The default region information is 0 by default. Region information supports complete customization. For example, you can add data with specific business needs in the region, such as GPS information/International Unified Regional Information Code/Postal Code, etc. That is to say, you can use ip2region to manage your own IP location data.
The xdb
format generation program will automatically deduplicate and compress some data. By default, all IP data is generated. The generated ip2region.xdb database is 11MiB. As the detail of the data increases, the size of the database gradually increases.
Even for queries based entirely on xdb
files, the response time for a single query is at the ten microsecond level. Memory accelerated queries can be turned on in the following two ways:
vIndex
index cache: Use a fixed 512KiB
memory space to cache vector index data, reduce one IO disk operation, and keep the average query efficiency stable between 10-20 microseconds.xdb
entire file cache: Load the entire xdb
file into memory. The memory usage is equal to the size of the xdb
file. There is no disk IO operation and microsecond-level query efficiency is maintained.xdb
data query For API introduction, usage documentation and test procedures, please refer to the ReadMe introduction under the corresponding searcher
query client. The implementation of all query bindings is as follows:
Ok? | state | programming language | describe | Contributor |
---|---|---|---|---|
✅ | Completed | golang | golang xdb query client implementation | Lion |
✅ | Completed | php | PHP xdb query client implementation | Lion |
✅ | Completed | java | Java xdb query client implementation | Lion |
✅ | Completed | lua | Pure Lua xdb query client implementation | Lion |
✅ | Completed | c | ANSC c xdb query client implementation | Lion |
✅ | Completed | lua_c | Lua c extended xdb query client implementation | Lion |
✅ | Completed | rust | rust xdb query client implementation | gongzhengyang |
✅ | Completed | python | python xdb query client implementation | Awesome Huahua |
✅ | Completed | nodejs | nodejs xdb query client implementation | Wu Jian Ping |
✅ | Completed | csharp | csharp xdb query client implementation | Alan Lee |
✅ | Completed | erlang | Erlang xdb query client implementation | leihua996 |
To be started | php_ext | PHP c extension xdb query client implementation | To be determined | |
✅ | Completed | nginx | nginx extends xdb query client implementation | Wu Jian Ping |
✅ | Completed | C++ | C++ xdb query client implementation | Yunbin Liu |
The following toolchain implementations are contributed by community developers through third-party repositories:
Ok? | state | programming language | describe | Contributor |
---|---|---|---|---|
✅ | Completed | ruby-ip2region | ruby xdb query client implementation | jicheng1014 |
✅ | Completed | Ip2regionTool | ip2region data conversion tool | orestone |
xdb
data generation For API introduction, usage documentation and test procedures, please refer to the ReadMe document under maker
generation program below:
Ok? | state | programming language | describe | Contributor |
---|---|---|---|---|
✅ | Completed | golang | Golang xdb generation program implementation | Lion |
✅ | Completed | java | Java xdb generation program implementation | Lion |
To be started | c | ANSC c xdb generation program implementation | Lion | |
✅ | Completed | python | Python xdb generation program implementation | leolin49 |
✅ | Completed | csharp | csharp xdb generation program implementation | Alan Lee |
✅ | Completed | rust | rust xdb generator implementation | KevinWang |
✅ | Completed | C++ | C++ xdb generation program implementation | Yunbin Liu |
xdb
data update ip2region aims to study the design and implementation of IP data storage and fast query . It does not have the support of original IP data, and there will be no commercial version. The ./data/ip.merge.txt
original data that comes with this project has not been updated for a long time and will not be updated again. For usage scenarios that require high data accuracy and update frequency, it is recommended to purchase third-party commercial data. You can use There are several ways to try to update the data yourself:
You can use the editing tools provided by ip2region to modify it based on the original IP data of ./data/ip.merge.txt
that comes with ip2region. Currently, there are several ways to source data:
[数据源补充]
in ip2region Github/Gitee For how to use the original IP data editing tool, please refer to the ReadMe document under the maker
generation program below:
Ok? | state | programming language | describe | Contributor |
---|---|---|---|---|
✅ | Completed | golang | golang original IP data editor | Lion |
To be started | java | java raw IP data editor | Lion | |
✅ | Completed | C++ | C++ Raw IP Data Editor | Yunbin Liu |
If you want to update the data through your own API or data source, you can refer to the update algorithm基于检测算法
shared in the following video to write an update program yourself:
The entire cached query of xdb is concurrency-safe. File-based queries are not concurrency-safe. Different processes/threads/coroutines need to be used safely by creating different query objects. When the amount of concurrency is large, file-based queries The query method may cause an error with too many open files. Please modify the maximum number of open files allowed by the kernel (fs.file-max=a higher value), or load the entire xdb into memory for safe concurrent use.
Please follow the WeChat public account lionsoul-org (Lion’s Soul) first