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