可能的重复项:
如何在C#中从给定IP获取域名?
如何将 int 格式的 ip 地址转换为字符串格式。例如,我有这个 int 格式的 IP 地址,173.194.38.138
我想转换为字符串www.rugadingku.blogspot.com
.我看到了很多关于如何将 ip 字符串转换为 int 而不是 int 转换为字符串的示例。
您可以使用此代码将IP地址转换为主机名:
IPHostEntry IpToDomainName = Dns.GetHostEntry("173.194.38.138");
string hostname =IpToDomainName.HostName;
Dns.GetHostByAddress
您也可以使用这种方式:
System.Net.IPHostEntry ip = System.Net.Dns.GetHostByAddress("173.194.38.138");
string hostname = ip.HostName;
试试这个:未测试
访问 http://www.dijksterhuis.org/converting-an-ip-address-to-a-hostname-and-back-with-c/
// Map an IP address to a hostname
IPHostEntry IpToDomainName = Dns.GetHostEntry("209.85.173.99");
Console.WriteLine("DomainName: {0}", IpToDomainName.HostName);
也试试这个:
public static string getDNSName(string myIP)
{
System.Net.IPHostEntry ip = System.Net.Dns.GetHostByAddress(myIP);
return ip.HostName;
}