日期:2014-05-18 浏览次数:21316 次
string strHostName = Dns.GetHostName(); foreach (IPAddress ip in System.Net.Dns.GetHostAddresses(strHostName)) { Console.WriteLine(ip.ToString()); }
------解决方案--------------------
using System.Net.NetworkInformation; 。 。 。 NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces(); foreach (NetworkInterface ni in interfaces) { if (ni.NetworkInterfaceType == NetworkInterfaceType.Ethernet) { MessageBox.Show(ni.Name); } }
------解决方案--------------------
IPHostEntry hostInfo = Dns.GetHostByName(hostString);
hostInfo.AddressList[0];
------解决方案--------------------
ip = Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString()
ip = Request.ServerVariables["REMOTE_ADDR"].ToString()
------解决方案--------------------
//试试这个 NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces(); foreach (NetworkInterface ni in interfaces) { if (ni.NetworkInterfaceType == NetworkInterfaceType.Ethernet) { foreach (UnicastIPAddressInformation ip in ni.GetIPProperties().UnicastAddresses) { if (ip.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) { MessageBox.Show(ip.Address.ToString()); } } } }
------解决方案--------------------
另:由于微软的APIPA机制,可能会出现一个169.254.*.*这样的地址。。。