2012-12-10 37 views
2

可能重复:
How to get domain name from Given IP in C#?解决IP地址(INT)来命名

我如何转换IP地址INT格式字符串格式。 例如,我有这个IP地址在int格式,173.194.38.138,我想转换为字符串www.rugadingku.blogspot.com。我看到很多关于如何将ip字符串转换为int的示例,但是不能将int转换为字符串。

+0

好,你需要建立一个[查找表(http://en.wikipedia.org/wiki/Lookup_table) – BrOSs

+0

你知道一个IP可以在许多主机中共享,对吗? –

+4

http://stackoverflow.com/questions/3252845/how-to-get-domain-name-from-given-ip-in-c – Habib

回答

3

您可以使用此代码的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;