welcome to Qijie's Blog 薛其杰

如果你遇到这样的场景, 你知道远程机器的ip地址, 想要通过ip地址来获得主机名。可以使用.net的System.Net命名空间, 这里边有一个类是IPHostEntry, 使用方式如下:

 

IPHostEntry hostInfo = Dns.GetHostByAddress(IPAddress .Parse (@"127.60.78.20"));
Console.WriteLine(hostInfo.HostName.ToString());

 

若是通过主机名获得IP地址也是使用此类.

 

IPHostEntry hostbyname = Dns.GetHostByName("qixue01");
Console.WriteLine(hostbyname .AddressList [
0]);

 

 

posted on 2010-01-12 10:18  零点零一  阅读(1479)  评论(0)    收藏  举报