This is a public Component Interface for reading Pure IP database. I learned about the data format of pure IP database through luma's "Explanation of pure IP database format" and based on an IPLocation on the network. the dll source code is adapted. Why should I adapt this component? Because I see that the file stream is opened every time this component is used, and the entire interface uses static attributes. It is not suitable for multi-threaded concurrent queries in the Web environment and is not optimal in performance. With the luma format explanation and the source code of the existing IPLocation. dll, my work becomes abnormal and simple. A small error is solved after a debugging. Better performance than IPLocation. dll is also greatly improved, although there are only a few hundred lines of code, although there are a lot of similar code on the Internet, but inherit from my consistent practice, I still contribute this component open source. The following is an introduction to some interfaces:
Copy codeThe Code is as follows:
QQWry. NET. QQWryLocator qqWry = new QQWry. NET. QQWryLocator ("qqwry. dat"); // initialize the database file and obtain the number of IP records, which can be obtained through Count
QQWry. NET. IPLocation ip = qqWry. Query ("120.67.217.7"); // Query an ip address
Console. WriteLine ("{0} {1} {2}", ip. IP, ip. Country, ip. Local );
The following is the performance comparison code with IPLocation. dll:
Copy codeThe Code is as follows:
Stopwatch stopwatch = new Stopwatch ();
List <string> ips = new List <string> {"218.5.3.128", "success", "125.78.67.175", "220.250.64.23", "218.5.3.128", "success", "125.78.67.175 ", "220.250.64.23 "};
Stopwatch. Start ();
For (int I = 0; I <100; I ++)
{
Foreach (string item in ips)
{
Ip = qqWry. Query (item );
// Console. WriteLine ("{0} {1} {2}", ip. IP, ip. Country, ip. Local );
}
}
Stopwatch. Stop ();
Console. WriteLine ("QQWryLocator spent {0} ms", stopwatch. ElapsedMilliseconds );
Stopwatch. Reset ();
Stopwatch. Start ();
For (int I = 0; I <100; I ++)
{
Foreach (string item in ips)
{
String s = IPLocation. IPLocation. IPLocate ("qqwry. dat", item );
// Console. WriteLine (s );
}
}
Stopwatch. Stop ();
Console. WriteLine ("IPLocation spent {0} ms", stopwatch. ElapsedMilliseconds );
Performance Comparison results:
Download source code and example