.Net如何获取IP地址?这篇文章主要介绍了.Net获取IP地址的方法,本文给大家介绍的非常不错,具有一定的参考借鉴价值,感兴趣的用户就来一聚教程网参考一下吧!
获取本机IP
2.获取网页客户端IP
////// 获取IPv4地址 /// ///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; }