• Asp.net获取客户端的IP地址排除::1


    public static string GetClientIPv4Address()
            {
                string ipv4 = String.Empty;

                foreach (IPAddress ip in Dns.GetHostAddresses(GetClientIP()))
                {
                    if (ip.AddressFamily.ToString() == "InterNetwork")
                    {
                        ipv4 = ip.ToString();
                        break;
                    }
                }

                if (ipv4 != String.Empty)
                {
                    return ipv4;
                }
                // 利用 Dns.GetHostEntry 方法,由获取的 IPv6 位址反查 DNS 纪录,
                // 再逐一判断何者为 IPv4 协议,即可转为 IPv4 位址。
                foreach (IPAddress ip in Dns.GetHostEntry(GetClientIP()).AddressList)
                //foreach (IPAddress ip in Dns.GetHostAddresses(Dns.GetHostName()))
                {
                    if (ip.AddressFamily.ToString() == "InterNetwork")
                    {
                        ipv4 = ip.ToString();
                        break;
                    }
                }

                return ipv4;
            }
            public static string GetClientIP()
            {
                if (null == HttpContext.Current.Request.ServerVariables["HTTP_VIA"])
                {
                    return HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
                }
                else
                {
                    return HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
                }
            }

  • 相关阅读:
    Android:SurfaceView和View 区别
    放下这8件事 就离成功不远了
    Android 的参考资料地址
    Java内存分配原理(二)
    J2ME最佳实践之联网开发编写反应灵敏的联网提示界面
    [转载]正则表达式学习
    Java内存分配原理(三)
    flashpaper2.2 asp.net win2003 iis 配置解决方案
    ubuntu ip地址,jdk,ssh配置
    office 2007 打开xls提示格式不正确
  • 原文地址:https://www.cnblogs.com/kingvi/p/12869262.html
Copyright © 2020-2023  润新知