日期:2014-05-18 浏览次数:20800 次
static string GetIpAddress(string hostName) { IPHostEntry iphost = Dns.GetHostEntry(hostName); foreach (IPAddress var in iphost.AddressList) { if (var.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) { return var.ToString(); } } return iphost.AddressList[0].ToString(); } //usage string ip = GetIpAddress("localhost");
------解决方案--------------------
System.Net.IPAddress.IPv6Loopback的值为"::1"