首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C# 在局域网里依据IP获取对应计算机名字

2012-11-17 
C# 在局域网里根据IP获取对应计算机名字string computernameDns.GetHostEntry(textBox1.Text).HostName/

C# 在局域网里根据IP获取对应计算机名字
 
  string computername= Dns.GetHostEntry(textBox1.Text).HostName;//textBox1.Text写入自己的IP
   
  或者 string computername= Dns.GetHostEntry(“”).HostName 能够获取到自己电脑的名字

  可是现在我要获取局域网的计算机的名字,所有IP已获取了,可是不行,哪位高手指点一下,因为我要同时显示IP和计算机的名字,如果单独获取计算机的名字也实现了。现在就是要输入一个IP就能得到计算机的名字。

[解决办法]


C#的局域网扫描工具
http://www.codeproject.com/KB/cs/c__ip_scanner.aspx
[解决办法]
遍历局域网获取IP和HostName的方法

C# code
void Find( ) //     {      Add( "-- >>> >> >>> Found station <<< << <<< -- " );      int lastF = ipFrom.Text.LastIndexOf(".");      int lastT = ipTo.Text.LastIndexOf(".");      string frm = ipFrom.Text.Substring(lastF+1);      string tto = ipTo.Text.Substring(lastT+1);      int result = 0;      System.Diagnostics.Debug.WriteLine( frm + " " + tto);      for( int i = int.Parse( frm); i <= int.Parse(tto );i++)      {        try        {          string address = ipTo.Text.Substring(0,lastT+1);          System.Diagnostics.Debug.WriteLine(ipTo.Text.Substring(0,lastT+1)+i);          IPHostEntry he = Dns.GetHostByAddress( address+i);          Add( he.HostName );          result += 1;        }        catch( SocketException )        {          // in cazul unei erori        }        catch( Exception )        {          // previne bloacarea programului        }      }    }
[解决办法]
探讨
唉 大家好,好几天没有上网,才看见,你们理解有误呀,我是说已经获得到了IP,要获取该IP的计算机的名字。

热点排行