To read the common component interface of pure IP database qqwry.net_ practical skills

Source: Internet
Author: User
This is a pure IP database to read the common component interface, I was through the luma "pure IP database format detailed" to understand the pure IP database data format, and based on a network of IPLocation.dll source based on the basis of the adaptation. Why do I have to adapt this component? Because I see this component in use, every time you open the file stream, and the entire interface uses static properties. It is not suitable for the requirement of multithread concurrent query in Web environment, and it is not optimal in performance. With the Luma format, and the existing IPLocation.dll of the source code, so that my work became unusually simple. A small error occurred, but also after a debugging on the solution. Performance than IPLocation.dll also has a greater improvement, although only a short line of hundreds of lines of code, although there are many similar code on the Web, but inherit my usual practice, I still have this component open source contribution. The following is an introduction to the use of some interfaces:
Copy Code code as follows:

QQWry.NET.QQWryLocator Qqwry = new QQWry.NET.QQWryLocator ("Qqwry.dat")//initializes the database file and obtains the number of IP records, which can be obtained by count
QQWry.NET.IPLocation IP = qqwry.query ("120.67.217.7"); Querying 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 Code code as follows:

Stopwatch stopwatch = new stopwatch ();
list<string> ips = new List<string> {"218.5.3.128", "120.67.217.7", "125.78.67.175", "220.250.64.23", " 218.5.3.128 "," 120.67.217.7 "," 125.78.67.175 "," 220.250.64.23 "};
Stopwatch. Start ();
for (int i = 0; i < 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 < 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:

source code and sample downloads

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.