C # First formal application, ASP. NET Hunt the rest edition!
This program, the day before yesterday I bought the Visual Studio.NET Beta 2 Chinese version of the first formal program written, I feel just really good!!
The Hunt's code refers to the asp.net of the flying cutter, but his article is for the. NET framework Beta1, and BETA2 many places have been modified, by the way also added to the program list IP function, That is to say, multiple IP addresses for a host can be listed. Just the IP location of the site based on the function of the temporary did not do, because I used the machine is a friend, and no IP database at hand: ~ (
static void Main ()
{
Application.Run (New Form1 ());
}
private void Cmdexec_click (object sender, System.EventArgs e)
{
IPAddress Theip;
Txthostname.focus ();
if (txthostname.text.length==0)
{
MessageBox.Show ("You can enter the IP or host name you want to hunt!") But cannot be empty "," system prompts ");
Return False
}
Try
{
int i = 0;
int n = dns.resolve (txtHostname.Text.ToString ()). Addresslist.getlength (0);
IPListbox.Items.Clear ();
for (; i<n;i++)
{
IPLISTBOX.ITEMS.ADD (Dns.resolve (txtHostname.Text.ToString ()). Addresslist.getvalue (i). ToString ());
}
Theip = (IPAddress) dns.resolve (TxtHostname.Text.ToString ()). Addresslist.getvalue (0);
Lblipinfo.text = Theip.tostring ();
if (check1. Checked==true)
{//
Lblsystem.text = "Detection ...";
Lblhttp.text = "Detection ...";
Lblftp.text = "Detection ...";
Lbldns.text = "Detection ...";
Lbltelnet.text = "Detection ...";
Lblsmtp.text = "Detection ...";
Lblpop.text = "Detection ...";
Check Service
Detectservice (THEIP);
Detectport (THEIP);
Lblsystem.text = Strsystem.tostring ();
Lblhttp.text = Strhttp.tostring ();
Lblftp.text = Strftp.tostring ();
Lbldns.text = Strdns.tostring ();
Lbltelnet.text = Strtelnet.tostring ();
Lblsmtp.text = Strsmtp.tostring ();
Lblpop.text = Strpop.tostring ();
}
if (Check2. Checked==true)
{
Check IP area, not implemented
}
}
Catch
{
MessageBox.Show ("This host cannot connect Oh!\r\n Please re-enter a correct!") "," System hints ");
Txthostname.text = "";
Txthostname.focus ();
Lblipinfo.text = "Unable to connect or convert IP, the location is probably outside the planet!";
Lblsystem.text = "on standby ...";
Lblhttp.text = "on standby ...";
Lblftp.text = "on standby ...";
Lbldns.text = "on standby ...";
Lbltelnet.text = "on standby ...";
Lblsmtp.text = "on standby ...";
Lblpop.text = "on standby ...";
}
Return
}
private void Detectservice (IPAddress theip)
{
String tFtp = Tcpconnect (theip,21); is FTP service
String ttelnet = Tcpconnect (theip,23); is Telnet service
String tdns = Tcpconnect (theip,43); is Dns service
String tpop = Tcpconnect (theip,110); is POP3 service
String tsmtp = Tcpconnect (theip,25); is Mail SMTP Service
if (tftp!= "None") strftp = TFTP;
if (ttelnet!= "None") strtelnet = ttelnet;
if (tdns!= "None") Strdns = Tdns;
if (tpop!= "None") Strpop = Tpop;
if (tsmtp!= "None") strsmtp = TSMTP;
TcpClient TCP = new TcpClient ();
Tcp. Connect (theip,80);
int Thttpstart;
String thttp;
String tmsg = "Post/index.htm http/1.1\r\n" +
"Connection:keep-alive\r\n\r\n";
Stream sm = tcp. GetStream ();
Sm. Write (Encoding.Default.GetBytes (Tmsg.tochararray ()), 0,tmsg.length);
StreamReader sr = new StreamReader (TCP. GetStream (), encoding.default);
while (Sr. Peek ()!=-1)
{
thttp= Sr. ReadLine ();
Thttpstart = Thttp.indexof ("Server");
if (thttpstart!=-1)
{
Strhttp = thttp;
Break
}
}
Tcp. Close ();
}
private String Tcpconnect (IPAddress theip,int Port)
{
TcpClient TCP = new TcpClient ();
StreamReader SR;
string result;
Try
{
Checked
{
Tcp. Connect (Theip,port);
sr = new StreamReader (TCP. GetStream (). ToString (), encoding.default);
result = Sr. ReadLine (). ToString ();
Tcp. Close ();
}
}
Catch
{
result = "None";
}
return result;
}
private void Detectport (IPAddress theip)
{
Is
if (Strhttp.indexof ("Microsoft")!=-1)
{
Strsystem = "Windows";
if (Strhttp.indexof ("IIS")!=-1)
{
strsystem= "Windows nt/2000";
if (Strhttp.indexof ("5.0")!=-1)
Strsystem= "Windows 2000";
Else
strsystem= "Windows NT";
}
}
else if (Strhttp.indexof ("Apache")!=-1)
{
Strsystem = "Unix/linux";
if (Strhttp.indexof ("Unix")!=-1)
Strsystem= "Unix";
}
Else
{
if (Tcpconnect (theip,139)!= "None")
strsystem= "Windows 98/me";
else if (Tcpconnect (theip,1433)!= "None")
strsystem= "Windows nt/2000";
Else
Strsystem= "Windows/linux/unix";
}
}
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.