10 microsecond performance! Offline IP address library developed by C#

10 microsecond performance! Offline IP address library developed by C#

ip2 region v2.0 -is an offline IP address location library and IP location data management framework with a query efficiency of 10 microseconds. It provides xdb data generation and query client implementation in many major programming languages.

最后更新 7/7/2023 1:08 AM
工具箱
预计阅读 3 分钟
分类
.NET
标签
.NET C#

What is Ip2 region?

ip2 region v2.0 -is an offline IP address location library and IP location data management framework with a query efficiency of 10 microseconds. It provides xdb data generation and query client implementation in many major programming languages.

application scenarios

Ip2 region is widely used in various scenarios that require IP address location. For example, it can be used to detect and prevent attacks from IP addresses in certain regions or countries, and can locate specific geographical locations based on users 'IP addresses. Data analysis and statistics can be performed based on the geographical location information of IP addresses, such as counting the number of users in a certain area.

functional properties

1. Standardized data format

The region information of each IP data segment has a fixed format: country| regional| provinces| city| ISP, only most of the data of China is accurate to the city, some data of other countries can only be located to the country, and the options before and after are all 0.

2. Data deduplication and compression

The xdb format generator will automatically deduplicate and compress some data. By default, all IP data will be generated. The ip2region.xdb database is 11MiB. As the data detail increases, the database size will gradually increase.

3. Speed query response

Even for queries based entirely on xdb files, the response time for a single query is ten microseconds. Memory accelerated queries can be enabled in the following two ways:

vIndex index caching: Use a fixed memory space of 512KiB to cache vector index data, reducing one IO disk operation and keeping the average query efficiency stable between 10-20 microseconds. xdb entire file cache: Load the entire xdb file into memory, and the memory consumption is equivalent to the xdb file size. There is no disk IO operation, and maintain microsecond query efficiency.

4. IP data management framework

xdb in v2.0 format supports hundreds of millions of IP data segment lines, and region information can also be completely customized. For example, you can add data for specific business requirements to the region, such as GPS information/international unified regional information code/zip code, etc. That means you can completely use ip2 region to manage your own IP location data.

How to use it in C#?

  1. Install the NuGet package IP2Region.Net.
Install-Package IP2Region.Net
  1. Query using API is very simple!
using IP2Region.Net.XDB;

Searcher searcher = new Searcher();
searcher.Search("IP地址");

** Dependency injection **

services.AddSingleton<ISearcher,Searcher>();

** Performance **

project address

https://github.com/lionsoul2014/ip2region

Keep Exploring

延伸阅读

更多文章
同分类 / 同标签 4/22/2026

Support for. NET by operating system versions (250707 update)

Use virtual machines and test machines to test the support of each version of the operating system for. NET. After installing the operating system, it is passed by measuring the corresponding running time of the installation and being able to run the Stardust Agent.

继续阅读
同分类 / 同标签 2/7/2026

Summary of experience in using AOT

From the very beginning of project creation, you should develop a good habit of conducting AOT release testing in a timely manner whenever new features are added or newer syntax is used.

继续阅读