网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > ASP.NET实例
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.C#+ASP.NET开发基于Web的RSS阅读.
.将上传图片打上防伪图片水印并写.
.ASP.Net实现将Word转换PDF格式.
.asp.net 上传大文件控件.
.做完一个小网站的一点经验总结(2.
.利用ASP.NET构建网上考试系统.
.用ASP.Net写一个发送ICQ信息的程.
.隨心所欲產生圖案.
.用Asp.net实现基于XML的留言簿之.
.ASP.NET 2.0中构造个性化网页.
.用Asp.net实现基于XML的留言簿之.
.基于asp.net的webmenu的数据操作1.
.在.NET 应用程序中用System.Web..
.ASP.NET中动态修改web.config中的.
.在DataSet中建立外键约束.
.如何建立自己的新闻发布系统?.
.保存美丽记忆 用ASP.NET创建网络.
.做完一个小网站的一点经验总结(1.
.ASP.NET读取POP3邮件的操作.
.用ASP.NET和XML做的新闻系统.

ASP.NET追捕休整版

发表日期:2003-12-29


   C#第一个正式应用,ASP.NET追捕休整版!
 这个程序,是前天我买到Visual Studio.net beta 2 中文版后编写的第一个正式程序,感觉只真是好极了!!
 
 这个追捕的代码参考过飞刀的ASP.NET 追捕的文章,但他文章中是针对.NET 框架beta1的,而BETA2中好多的地方都修改调整了,顺便也给程序增加了列表IP的功能,也就是说主机的多个IP地址都可以列出来的.只是那个根据IP查到IP所在地的功能暂时没做,因为当时我用的机器是朋友的,而手头没有IP数据库:~(
 
 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或者主机名称!但不能为空","系统提示");
 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 所在地区,未实现
 }
 }
 catch
 {
 MessageBox.Show("这个主机无法连接哦!\r\n请重新输入一个正确的吧!","系统提示");
 txtHostname.Text = "";
 txtHostname.Focus();
 lblIpInfo.Text = "无法连接或转换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()+",所在地查询未实现!";
 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.)

下一篇:ASP.NET的用户控件 人气:12133
浏览全部ASP.NET的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐