在本機運行可以得到主機名,上傳到服務器後 傳入值為IP,返回值同樣為IP
服務器環境:windows 2003 ,.net framework 2.0
谁能解答一下原因?TKS,代碼如下public string GetHostNameByIp(string ip)
        {
            ip = ip.Trim();
            if (ip == string.Empty)
                return string.Empty;
            try
            {
                    System.Net.IPHostEntry host = System.Net.Dns.GetHostEntry(IPAddress.Parse(ip));
                    return host.HostName;
            }
            catch (Exception)
            {
                return string.Empty;
            }
        }

解决方案 »

  1.   

    GetHostEntry 方法在 DNS 服务器中查询与某个主机名或 IP 地址关联的 IP 地址。当传递一个空字符串作为主机名时,此方法返回本地主机的 IPv4 地址。
      

  2.   

    public static void DoGetHostEntry(string hostname)
    {
        IPHostEntry host;    host = Dns.GetHostEntry(hostname);    Console.WriteLine("GetHostEntry({0}) returns:", hostname);    foreach (IPAddress ip in host.AddressList)
        {
            Console.WriteLine("    {0}", ip);
        }
    }
      

  3.   

    可能是服务器hosts设置的问题
      

  4.   

    還是不對,在windows 2000 上可以獲得主機名,而在windows 2003 上不可以,是不是windws 2003上要在哪裡設置一下?