Asp. NET Hunt and Rest edition

Source: Internet
Author: User
Tags getstream connect readline tostring visual studio linux
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 Form1_Load (object sender, System.EventArgs e)
{
String Localhost = System.Net.Dns.GetHostName ();
int i = 0;
int n = dns.resolve (localhost.tostring ()). Addresslist.getlength (0);
Lblipinfo.text = localhost.tostring () + ", that's you!";
Txthostname.text = Dns.resolve (localhost.tostring ()). Addresslist.getvalue (0). ToString ();
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 ...";
for (; i<n;i++)
{
IPLISTBOX.ITEMS.ADD (Dns.resolve (localhost.tostring ()). Addresslist.getvalue (i). ToString ());
}
}

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";
}
}

private void Iplistbox_selectedindexchanged (object sender, System.EventArgs e)
{
Lblipinfo.text = IPListbox.Text.ToString () + ", location query not implemented!";
Txthostname.text = IPListbox.Text.ToString ();
}

private void Button1_Click (object sender, System.EventArgs e)
{
Application.exit ();
}

private void Linklabel1_linkclicked (object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
{
Linklabel1.show ();
}


Complete code and compiled programs: Http://202.103.224.224/icools/bbs/non-cgi/usr/5_2.zip

Remember to be sure to install. NET FRAMEWORKSDK Beta2

I am a beginner, have questions to study together!

by She (S.F.)


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.