.Net如何获取IP地址 .Net获取IP地址的方法
获取本机IP
获取网页客户端IP
获取网页IP
public static string GetIP4Address(HttpRequest request = null) { Func f = e => e.AddressFamily.ToString() == "InterNetwork"; IPAddress ipa = Dns.GetHostAddresses((request ?? HttpContext.Current.Request).UserHostAddress).FirstOrDefault(f) ?? Dns.GetHostAddresses(Dns.GetHostName()).FirstOrDefault(f); if (ipa != null) { return ipa.ToString(); } return HttpContext.Current.Request.UserHostAddress; }