Get IPv4 addresses from Dns.GetHostEntry()

前端 未结 7 1557
长发绾君心
长发绾君心 2020-11-27 04:49

I\'ve got some code here that works great on IPv4 machines, but on our build server (an IPv6) it fails. In a nutshell:

IPHostEntry ipHostEntry = Dns.GetHost         


        
7条回答
  •  星月不相逢
    2020-11-27 05:25

    To find all valid address list this is the code I have used

    public static IEnumerable GetAddresses()
    {
          var host = Dns.GetHostEntry(Dns.GetHostName());
          return (from ip in host.AddressList where ip.AddressFamily == AddressFamily.lo select ip.ToString()).ToList();
    }
    

提交回复
热议问题