.Net获取IP地址

╄→гoц情女王★ 提交于 2020-01-13 21:25:23

来自森大科技官方博客
http://www.cnsendblog.com/index.php/?p=292
GPS平台、网站建设、软件开发、系统运维,找森大网络科技!
http://cnsendnet.taobao.com

1.获取本机IP
在这里插入图片描述
2.获取网页客户端IP
在这里插入图片描述
///
/// 获取IPv4地址
///
///
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;
    }

来自森大科技官方博客
http://www.cnsendblog.com/index.php/?p=292
GPS平台、网站建设、软件开发、系统运维,找森大网络科技!
http://cnsendnet.taobao.com

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!