国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設計 > 正文

ASP.NET追捕休整版

2019-11-18 19:52:49
字體:
供稿:網(wǎng)友
   C#第一個正式應用,asp.net追捕休整版!
 這個程序,是前天我買到Visual Studio.net beta 2 中文版后編寫的第一個正式程序,感覺只真是好極了!!
 
 這個追捕的代碼參考過飛刀的ASP.NET 追捕的文章,但他文章中是針對.NET 框架beta1的,而BETA2中好多的地方都修改調(diào)整了,順便也給程序增加了列表ip的功能,也就是說主機的多個IP地址都可以列出來的.只是那個根據(jù)IP查到IP所在地的功能暫時沒做,因為當時我用的機器是朋友的,而手頭沒有IP數(shù)據(jù)庫:~(
 
 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()+",就是你啊!";
 txtHostname.Text = Dns.Resolve(Localhost.ToString()).AddressList.GetValue(0).ToString();
 lblSystem.Text = "待命中...";
 lblHttp.Text = "待命中...";
 lblFtp.Text = "待命中...";
 lblDns.Text = "待命中...";
 lblTelnet.Text = "待命中...";
 lblSmtp.Text = "待命中...";
 lblPop.Text = "待命中...";
 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("您可以輸入要追捕的IP或者主機名稱!但不能為空","系統(tǒng)提示");
 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 = "檢測中...";
 lblHttp.Text = "檢測中...";
 lblFtp.Text = "檢測中...";
 lblDns.Text = "檢測中...";
 lblTelnet.Text = "檢測中...";
 lblSmtp.Text = "檢測中...";
 lblPop.Text = "檢測中...";
 //檢查服務
 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)
 {
 //查IP 所在地區(qū),未實現(xiàn)
 }
 }
 catch
 {
 MessageBox.Show("這個主機無法連接哦!/r/n請重新輸入一個正確的吧!","系統(tǒng)提示");
 txtHostname.Text = "";
 txtHostname.Focus();
 lblIpInfo.Text = "無法連接或轉(zhuǎn)換IP,所在地大概是外星球!";
 lblSystem.Text = "待命中...";
 lblHttp.Text = "待命中...";
 lblFtp.Text = "待命中...";
 lblDns.Text = "待命中...";
 lblTelnet.Text = "待命中...";
 lblSmtp.Text = "待命中...";
 lblPop.Text = "待命中...";
 }
 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()+",所在地查詢未實現(xiàn)!";
 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();
 }
 
 
 完整的代碼和編譯過的程序:http://202.103.224.224/icools/bbs/non-cgi/usr/5_2.zip
 
 記得一定要裝 .NET FrameworkSDK beta2
 
 我是初學者,有問題一起研究!
 
 by 蕭寒雪(S.F.)

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 星座| 宁陵县| 招远市| 临沂市| 沾益县| 武功县| 霍邱县| 乐清市| 三穗县| 怀宁县| 龙南县| 中山市| 浦北县| 六盘水市| 望都县| 龙泉市| 四平市| 克拉玛依市| 淮阳县| 临汾市| 隆昌县| 临泉县| 长治市| 饶平县| 蕉岭县| 关岭| 兰坪| 丁青县| 靖西县| 云安县| 长丰县| 隆林| 南和县| 神农架林区| 华宁县| 淳安县| 威远县| 若尔盖县| 龙江县| 恩平市| 广东省|