zoukankan      html  css  js  c++  java
  • 用于获取因用cdn无法获取用户真实IP的方法

    不多说,具体方法如下,网上找的

        /// <summary>
        /// 用于获取因用cdn无法获取用户真实IP的方法
        /// </summary>
        /// <returns></returns>
        public  string GetCdnIp()
        {
            try
            {
                if (HttpContext.Current == null
                    || HttpContext.Current.Request == null
                    || HttpContext.Current.Request.ServerVariables == null)
                    return "";
                string customerIP = "";
                //CDN加速后取到的IP simone 090805
                customerIP = HttpContext.Current.Request.Headers["Cdn-Src-Ip"];
                if (!string.IsNullOrEmpty(customerIP))
                {
                    return customerIP;
                }
                if (HttpContext.Current.Request.ServerVariables["HTTP_VIA"] != null)
                {
                    customerIP = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
                    if (customerIP == null)
                        customerIP = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
                }
                else
                {
                    customerIP = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
                }
                if (string.Compare(customerIP, "unknown", true) == 0)
                    return HttpContext.Current.Request.UserHostAddress;
                return customerIP;
                /** lcq
                关键就在HTTP_X_FORWARDED_FOR
                使用不同种类代理服务器,上面的信息会有所不同:
                一、没有使用代理服务器的情况:
                REMOTE_ADDR = 您的 IP
                HTTP_VIA = 没数值或不显示
                HTTP_X_FORWARDED_FOR = 没数值或不显示
                二、使用透明代理服务器的情况:Transparent Proxies
                REMOTE_ADDR = 代理服务器 IP
                HTTP_VIA = 代理服务器 IP
                HTTP_X_FORWARDED_FOR = 您的真实 IP
                这类代理服务器还是将您的信息转发给您的访问对象,无法达到隐藏真实身份的目的。
                三、使用普通匿名代理服务器的情况:Anonymous Proxies
                REMOTE_ADDR = 代理服务器 IP
                HTTP_VIA = 代理服务器 IP
                HTTP_X_FORWARDED_FOR = 代理服务器 IP
                隐藏了您的真实IP,但是向访问对象透露了您是使用代理服务器访问他们的。
                四、使用欺骗性代理服务器的情况:Distorting Proxies
                REMOTE_ADDR = 代理服务器 IP
                HTTP_VIA = 代理服务器 IP
                HTTP_X_FORWARDED_FOR = 随机的 IP
                告诉了访问对象您使用了代理服务器,但编造了一个虚假的随机IP代替您的真实IP欺骗它。
                五、使用高匿名代理服务器的情况:High Anonymity Proxies (Elite proxies)
                REMOTE_ADDR = 代理服务器 IP
                HTTP_VIA = 没数值或不显示
                HTTP_X_FORWARDED_FOR = 没数值或不显示
                **/
            }
            catch
            {
                return string.Empty;
            }
        }

  • 相关阅读:
    针式PKM软件进入华军分类下载月排名前6名
    读取xml
    一个简单的记事本程序
    python输出重定向
    重看ATL布幔之下的秘密
    nginx学习(二)动态加载各模块
    ngx_queue的理解
    nginx学习(三)IOCP的使用
    nginx学习(一)内存
    使用python实现一个通用协议测试工具
  • 原文地址:https://www.cnblogs.com/xingvskong11/p/2724881.html
Copyright © 2011-2022 走看看