zoukankan      html  css  js  c++  java
  • 客户端IP

    http代理相关知识

    关键就在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 = 您的

     String ip = HttpContext.Current.Request.ServerVariables["X-Forwarded-For"];
                if (ip == null || ip.Length == 0 || string.Compare("unknown",ip,true)==0)
                {
                    ip = HttpContext.Current.Request.ServerVariables["Proxy-Client-IP"];
                }
                if (ip == null || ip.Length == 0 || string.Compare("unknown",ip,true)==0)
                {
                    ip = HttpContext.Current.Request.ServerVariables["WL-Proxy-Client-IP"];
                }
                if (ip == null || ip.Length == 0 || string.Compare("unknown",ip,true)==0)
                {
                    ip = HttpContext.Current.Request.ServerVariables["HTTP_CLIENT_IP"];
                }
                if (ip == null || ip.Length == 0 || string.Compare("unknown",ip,true)==0)
                {
                    ip = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
                }
                if (ip == null || ip.Length == 0 || string.Compare("unknown",ip,true)==0)
                {
                   // ip = HttpContext.Current.Request.getRemoteAddr();   
                    ip = HttpContext.Current.Request.ServerVariables.Get("Remote_Addr").ToString();

                }
                return ip;

  • 相关阅读:
    Python3之命令行参数处理
    基于 Laradock 环境 Project 的总结
    Typora功能新发现-自动复制图片到指定目录下
    ubuntu 18.04 设置静态ip方法
    vscode 同时编辑多处,多个光标 快捷键
    nginx和ftp搭建图片服务器
    Centos 6.5出现yum安装慢的情况
    Linux中的CentOS 6克隆之后修改
    springMVC-文件上传CommonsMultipartFile
    Spring和mybatis整合 org.mybatis.spring.mapper.MapperScannerConfigurer
  • 原文地址:https://www.cnblogs.com/kingwangzhen/p/1648443.html
Copyright © 2011-2022 走看看