Send a self-written C# IP location query program, which can use the Qingzhen/CoralWry.dat database (QQWry.dat/CoralWry.dat). The actual use value of the program may not be great, and it is only used as a reference for this type of C# program.
Some friends use the constructor/destructor of dynamic class objects in C# to open/close data files when the object is initialized/released. Although this is a good oriented idea, the release time of the managed program object is not Definitely, especially the use of ASP.NET. On the one hand, this will cause a waste of resources because the open file is not released. More importantly, it may cause sharing conflicts caused by thread concurrency. In addition, if cache is used in ASP.NET The mechanism will increase the complexity of the program and reduce the independence and reusability of the module.
For these reasons, all static methods are used in the program. In fact, this is a C# program rewritten from another C++ program of mine. The call of the module is very simple. For example, use the CoralWry.dat data file in the current directory to query the IP address. 121.193.213.6, you can:
IpLocation ipl=IpLocation ipl=IpLocator.GetIpLocation("CoralWry.dat","121.193.213.246");
Console.WriteLine("IP address segment: "+IpLocator.IntToIpString(ipl.IpStart)+" - "+IpLocator.IntToIpString(ipl.IpEnd));
Console.WriteLine("IP location: "+ipl.Country+" "+ipl.City);
The return value is an IpLocation structure, containing 4 attributes: Country, City, IpStart/IpEnd IP segment start/end value (uint type, can be converted into a dotted IP string using the IntToIpString() function)
Expand