This article is a mirror article of machine translation, please click here to jump to the original article.

View: 5462|Reply: 4

[Tips] [Actual combat]. NET/C# offline IP address (home) locator library

[Copy link]
Posted on 2023-5-10 19:49:52 | | |
Requirements: Nowadays, the comment area of many websites can display the author's attribution address, that is, the IP attribution address of the author's evaluation, and there are generally two ways to query the address through IP, one is to regularly update the IP address library locally, and the other is to adjust some API interfaces (free or paid).

I wrote before that I used GeoLite2 to query IP addresses offline, and now it seems that it has been charged, as follows:

.net/c# uses the GeoLite2 IP database to get the address
https://www.itsvse.com/thread-4782-1-1.html

Of course, there are also some free IP libraries (Pure free IP libraryThe hyperlink login is visible.

This paper uses the ip2region database to query addresses through IP, ip2region v2.0 - is an offline IP address location database and IP location data management framework, with a query efficiency of 10 microseconds, and provides XDB data generation and query client implementations for many mainstream programming languages.

GitHub address:The hyperlink login is visible.

The region information for each IP data segment is in a fixed format:Country|region|province|city| ISPOnly most of China's data is subdivided into cities, and the data of other countries can only be located to countries, and the options in the back and front are all 0.

First, download "ip2region.xdb"File, address:The hyperlink login is visible.

Create a new .NET 6 console application, use nuget to introduce a library written by others, and the command is as follows:

The code is as follows:


China|0|Shanghai|Shanghai|Mobile

If you are a ASP.NET Core website, you can register for the service using the following code:


There are three configurations of CachePolicy in the constructor, as follows:

namespace IP2Region.Net.XDB;

public enum CachePolicy
{
    /// <summary>
    /// no cache , not thread safe!
    /// </summary>
    File,
    /// <summary>
    /// cache vector index , reduce the number of IO operations , not thread safe!
    /// </summary>
    VectorIndex,
    /// <summary>
    /// default cache policy , cache whole xdb file , thread safe
    /// </summary>
    Content
}

(End)




Previous:.NET Core high-performance queue Channels is used
Next:【Turn】100-person R&D team 10 billion sales scale technical architecture practice sharing
 Landlord| Posted on 2023-5-10 19:51:57 |
Attach the ip2region.xdb file:


ip2region.zip (4.17 MB, Number of downloads: 0, 售价: 2 粒MB)
 Landlord| Posted on 2023-5-10 20:15:15 |
X-Forwarded-For multiple IP addresses in the HTTP request header
https://www.itsvse.com/thread-9654-1-1.html
Posted on 2023-5-10 20:34:41 |
Learn to learn
Posted on 2023-5-24 09:07:37 |
Learn to learn!!
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com