JAVA获取真实IP地址(代理、F5、WebLogic、Apache)

public static String getRealIp(HttpServletRequest req, HttpServletResponse resp) {  
  
    String ip = req.getHeader("X-Forwarded-For");  
  
    if (ip != null) {  
        if (ip.indexOf(',') == -1) {  
            return ip;  
        }  
        return ip.split(",")[0];  
    }  
  
    if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {  
        ip = req.getHeader("Proxy-Client-IP");  
    }  
    if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {  
        ip = req.getHeader("WL-Proxy-Client-IP");  
    }  
    if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {  
        ip = req.getRemoteAddr();  
    }  
  
    return ip;  
}  

 

你可能感兴趣的:(weblogic)