Asp. NET Write Hunt method

Source: Internet
Author: User
asp.net 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 = "Can't find out";
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;
}

Regroup to become new 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 ();

Nip is the IP format we need.
The next thing you can do is look in the database for the IP segment that matches the IP condition you are taking:

String startip = Nip.substring (0,11);
String EndIP = Nip.substring (12,3);
String Dbstartip,dbendip;
Double Dblendip,dbldbstartip,dbldbendip;

Querying the database
String Strsel = "SELECT * from wry where Left (startip,11) = '" +startip+ "";
SqlConnection myconn = new SqlConnection (strconn);
SQLCommand Mycomm = new SQLCommand (strsel,myconn);
MyConn.Open ();
SqlDataReader Dr;
Mycomm.execute (out DR);
if (Dr. Read ())
{
To be able to trace IP after three paragraphs.
Todo
{
Dbstartip = dr["StartIP"]. ToString ();
Dbendip = dr["EndIP"]. ToString ();
Dbstartip = dbstartip.substring (12,3);
Dbendip = dbendip.substring (12,3);
Dblendip = Double.Parse (ENDIP);
Dbldbstartip = Double.Parse (Dbstartip);
Dbldbendip = Double.Parse (DBENDIP);
strresult = dr["COUNTRY"]. ToString () +dr["local". ToString ();
if ((Dbldbstartipdblendip {
Break
}
}
while (Dr. Read ());
}
Else
{
After three paragraphs does not exist, check two paragraph
StartIP = nip.substring (0,7);
EndIP = nip.substring (9,3);
Strsel = "SELECT * from wry where Left (startip,7) = ' +startip+" ' ORDER by startip Desc ';
SqlConnection cloneconn = (SqlConnection) Myconn.clone ();
SQLCommand Ocomm = new SQLCommand (strsel,cloneconn);
Cloneconn.open ();
SqlDataReader Odr;
Ocomm.execute (out ODR);
if (Odr.read ())
{
Dbstartip = odr["StartIP"]. ToString ();
Dbstartip = dbstartip.substring (9,3);
Dbldbstartip = Double.Parse (Dbstartip);
Dblendip = Double.Parse (ENDIP);
Todo
{
strresult=odr["COUNTRY"]. ToString () +odr["local". ToString ();
if (Dbldbstartip {
Break
}
}
while (Odr.read ());
}
Odr.close ();
Cloneconn.close ();
}
Dr. Close ();
Myconn.close ();

When querying the database, the method used by the flying cutter is to first check the first three paragraph matching records, if not, and then find the first two paragraphs matching records.
The program is very simple, I believe you can understand, here needs to be understood, the program in the use of flying knives DataReader instead of using a more powerful dataset, because this program only need to read data, and do not need to modify the database, delete, So using DataReader saves system resources than using datasets.



Test the program and test it on the local machine, as shown in Figure 3. It's over, my little secret on the mainframe is all made known: (

Because ASP.net and Visual C #, VC and other common use of a. NET object library, that is, as long as the logic is possible, then VC can do things, asp.net also can do. In other words, we this program, as long as a little modification, it can be made into a real pursuit of software, interested friends can have their own hands oh.

By writing this program, now I think no one will say "ASP." NET and ASP almost "bar.

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.