Get IP address from hostname in LAN(从 LAN 中的主机名获取 IP 地址)
问题描述
我找到了很多关于如何通过 IP 地址获取主机名的示例,如何获取局域网中主机的 IP 地址?
I found many samples on how to get a hostname by an IP address, how can I get the IP address of a host in the LAN?
推荐答案
试试这个
public static void DoGetHostAddresses(string hostname)
{
IPAddress[] ips;
ips = Dns.GetHostAddresses(hostname);
Console.WriteLine("GetHostAddresses({0}) returns:", hostname);
foreach (IPAddress ip in ips)
{
Console.WriteLine(" {0}", ip);
}
}
我从 http://msdn.microsoft.com/en-us/library/system.net.dns.gethostaddresses.aspx
这篇关于从 LAN 中的主机名获取 IP 地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!