获取本机IP 2.获取网页客户端IP /// summary /// 获取IPv4地址 /// /summary /// returns /returns public static string GetIP4Address(HttpRequest request = null) { FuncIPAddress, bool f = e = e.AddressFamily.ToString() == "InterNet
获取本机IP
2.获取网页客户端IP
/// <summary> /// 获取IPv4地址 /// </summary> /// <returns> </returns> public static string GetIP4Address(HttpRequest request = null) { Func<IPAddress, bool> 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; }
总结
以上所述是小编给大家介绍的.Net获取IP地址的方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对易盾网络网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!