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;

        }

  • 相关阅读:
    进程和线程(一)
    树和二叉树(一)
    栈和队列
    《Learning to Coordinate with Coordination Graphs in Repeated Single-Stage Multi-Agent Decision Problems》- ICML2018
    简单Socket网络通信
    Spring Websocket实现简易在线聊天功能
    Spring实现WebSocket通信
    Spring中配置使用slf4j + log4j
    构建web应用之——文件上传
    构建web应用之——SpringMVC实现CRUD
  • 原文地址:https://www.cnblogs.com/tianxuwei/p/10478983.html
Copyright © 2011-2022 走看看