zoukankan      html  css  js  c++  java
  • 获取客户端ip

    public String getRemortIP(HttpServletRequest request) {
            String ip = request.getHeader("x-forwarded-for");
            if ((ip == null) || (ip.length() == 0) || "unknown".equalsIgnoreCase(ip)) {
                ip = request.getHeader("Proxy-Client-IP");
            }
            if ((ip == null) || (ip.length() == 0) || "unknown".equalsIgnoreCase(ip)) {
                ip = request.getHeader("WL-Proxy-Client-IP");
            }
            if ((ip == null) || (ip.length() == 0) || "unknown".equalsIgnoreCase(ip)) {
                ip = request.getHeader("HTTP_CLIENT_IP");
            }
            if ((ip == null) || (ip.length() == 0) || "unknown".equalsIgnoreCase(ip)) {
                ip = request.getHeader("HTTP_X_FORWARDED_FOR");
            }
            if ((ip == null) || (ip.length() == 0) || "unknown".equalsIgnoreCase(ip)) {
                ip = request.getRemoteAddr();
            }
            return ip;
        }

    public String getRemortIP(HttpServletRequest request) {

            String ip = request.getHeader("x-forwarded-for");

            if ((ip == null) || (ip.length() == 0) || "unknown".equalsIgnoreCase(ip)) {

                ip = request.getHeader("Proxy-Client-IP");

            }

            if ((ip == null) || (ip.length() == 0) || "unknown".equalsIgnoreCase(ip)) {

                ip = request.getHeader("WL-Proxy-Client-IP");

            }

            if ((ip == null) || (ip.length() == 0) || "unknown".equalsIgnoreCase(ip)) {

                ip = request.getHeader("HTTP_CLIENT_IP");

            }

            if ((ip == null) || (ip.length() == 0) || "unknown".equalsIgnoreCase(ip)) {

                ip = request.getHeader("HTTP_X_FORWARDED_FOR");

            }

            if ((ip == null) || (ip.length() == 0) || "unknown".equalsIgnoreCase(ip)) {

                ip = request.getRemoteAddr();

            }

            returnip;

        }

  • 相关阅读:
    错误解决mysql
    (一)熟悉执行流程——基于ThinkPHP3.2的内容管理框架OneThink学习
    版权控制之zend guard 6.0使用教程
    IP进制站群原理
    多线程更新已排序的Datagridview数据,造成数据错位
    压缩html 减小存储空间
    DataGridView导入导出excel
    软件下载目录
    java反射
    JTA
  • 原文地址:https://www.cnblogs.com/tianxuwei/p/10478983.html
Copyright © 2011-2022 走看看