In writing programs, flying knives or let us see how the pursuit of IP to judge the source of the user (well, now will be uncovered "pursuit" of the "past", we listen carefully).
If you're going to write a hunt for software, I think the first thing you want to do is collect a list of IP allocations and store them in the database for reading. There is an IP allocation table in the Hunt software, but where is this table?
Oh, we know in the pursuit of the download contains two files, one for Wry.exe, this is the main program of the hunt, the second for Wry.dll, note that this is our hard to find the IP allocation table. But what kind of data file ends with a DLL? DLL file is not a dynamic link library?
No hurry, we went on to analyze, in the use of the pursuit of the process found that the program generated by the database more than DBF database, then this wry.dll is also a FoxPro database?
Think of it, immediately change the Wry.dll to WRY.DBF, and then open with Visual FoxPro, such as Figure 2, hehe, is a DBF database. It consists primarily of four field startip (Start IP), endip (end IP), Country (IP host country or province), local (user Internet type).
^&^ know these, the program is not difficult to write out, in a word, query the database.
Slowly, on the network with MDF database, whether some ...
Regardless of 3,721, convert MDF to SQL Server.
What the!? Will not convert MDF to SQL server?! Oh, this magazine is for programmers to see, these basic dongdong, or first look at other books, if you talk about these things, stray elder brother will scold me to cheat royalties: (
When you implement this feature, you use a function to do the same for the readability of the program:
public string GetIPFrom(string sIP)
{
......
}
In the previous program to get the IP is usually 202.101.96.54 this format, and in the IP Allocation table format is 202.101.096.054, so the first thing you need to do is to the IP segments of less than three bits of the partial supplement 0.
char[] de={'.'};
string[] aIP = sIP.Split(de);
string SingleIP;
StringBuilder nIPx = new StringBuilder();
int SIPLen;
string strResult = "查不出";
for(int i=0;i<4;i++)
{
SingleIP = aIP[i];
SIPLen = SingleIP.Length;
if(SIPLen<3)
{
for(int j=0;j<3-SIPLen;j++) SingleIP ="0"+SingleIP;
}
aIP[i] = SingleIP;
}
//重新组合成为新的IP
for(int i=0;i<aIP.Length;i++)
{
if(i!=aIP.Length-1)
{
nIPx.Append(aIP[i]+".");
}
else
{
nIPx.Append(aIP[i]);
}
}
string nIP = nIPx.ToString();