【问题标题】:resolve IP address(int) to name [duplicate]将IP地址(int)解析为名称[重复]
【发布时间】:2012-11-27 12:31:29
【问题描述】:

可能重复:
How to get domain name from Given IP in C#?

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

【问题讨论】:

  • 好吧,你需要建立一个lookup table
  • 你知道一个IP可以在很多很多主机之间共享,对吧?
  • 注意:此处列出的任何解决方案都不能保证有效。这样做依赖于反向 DNS,特定 IP 地址可能已设置也可能未设置。此外,您可能会得到一个意外的主机名,因为一个 IP 可以绑定到多个 DNS 名称/域

标签: c# string dns ip


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    试试这个:未测试

    访问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;
    }
    

    【讨论】:

      猜你喜欢
      • 2011-03-12
      • 2019-06-26
      • 1970-01-01
      • 2011-05-07
      • 2019-09-29
      • 1970-01-01
      • 1970-01-01
      • 2014-10-13
      • 2014-09-20
      相关资源
      最近更新 更多