Public Component Interface for reading Pure IP database QQWry. NET

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.