1回顶部 想必大家对小榕时光等扫描器都非常熟悉了,有没有自己写一个的冲动。最近微软推实施了.NET战略方案,C#是主推语言,你们是否有兴趣用C#来实现对局域网IP地址的扫描,尝试一下自己写的快乐,那么请跟我来。 目录 正文 private void buttion1_click(object sender,System.Event.Args e) { IPHostEntry myHost = new IPHostEntry(); Try { // Dns.GetHostName()获取本地计算机的主机名 // Dns.GetHostByName()获取指定 DNS 主机名的 DNS 信息 //得到本地主机的DNS信息 myHost = Dns.GetHostByName(Dns.GetHostName()); //显示本地主机名 textBox1.Text = myHost.HostName.ToString(); //显示本地主机的IP地址表 for(int i=0; i<myHost.AddressList.length;i++) { richTextBox1.AppendText(“本地主机IP地址->”+myHost.AddressList[i].ToString()+”\r”); } catch(Exception error) { MessageBox.Show(error.Message); } }//private Thread thScan = new thread(new ThreadStrart(ScanTarget)); //Thread.Start 方法:启动线程 thScan.Strart(); } private void ScanTarget() { // numericUpDown1是定义的System.Windows.Forms.NumericUpDown控件 string strIPAddress=numericUpDown1.Text+”.”+numericUpDown2.Text+”.”+numericUpDown3.Text+”.”; //开始扫描地址 int nStrat = Int32.Parse(numericUpDown4.Text); //终止扫描地址 int nEnd =Int32.Parse(numericUpDown5.Text); //扫描的操作 for(int i=nStrat;i<=nEnd;i++) { string strScanIPAdd = strIPAddress +i.ToString(); //转换成IP地址 IPAddress myScanIP = IPAddress.Parse(strScanIPAdd); try { //址获取 DNS 主机信息。 IPHostEntry myScanHost = Dns.GetHostByAddress(myScanIP); //获取主机的名 string strHostName =myScanHost.HostName.ToString(); richTextBox1.AppendText(strScanIPAdd+”->”+strHostName+”\r”); } catch(Exception error) { MessageBox.Show(error.Message); } }//for }//private |
正在阅读:C#实现网段扫描C#实现网段扫描
2004-04-08 14:39
出处:VChome
责任编辑:sdq