zoukankan      html  css  js  c++  java
  • 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"];
                }
            }

  • 相关阅读:
    Smart Client Architecture and Design Guide
    Duwamish密码分析篇, Part 3
    庆贺发文100篇
    .Net Distributed Application Design Guide
    New Introduction to ASP.NET 2.0 Web Parts Framework
    SPS toplevel Site Collection Administrators and Owners
    来自Ingo Rammer先生的Email关于《Advanced .Net Remoting》
    The newsletter published by Ingo Rammer
    深度探索.Net Remoting基础架构
    信道、接收器、接收链和信道接受提供程序
  • 原文地址:https://www.cnblogs.com/kingvi/p/12869262.html
Copyright © 2011-2022 走看看