.Net获取IP地址的方法
程序员文章站
2022-03-07 12:58:54
获取本机ip
2.获取网页客户端ip
///
/// 获取ipv4地址
///
获取本机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地址的方法,希望对大家有所帮助
上一篇: ASP.NET实现图片自动添加水印