struts 获取客户端真实ip

 

  
  
  
  
  1. HttpServletRequest request = (HttpServletRequest) ctx.get(AbstractHTTPDestination.HTTP_REQUEST); 
  2.  
  3. String ip = request.getHeader("Cdn-Src-Ip"); 
  4.  
  5. LOGGER.debug("Cdn-Src-Ip:" + ip); 
  6.  
  7. if (StringUtils.isBlank(ip) || "unknown".equalsIgnoreCase(ip)) { 
  8.  
  9. ip = request.getHeader("X-Forwarded-For"); 
  10.  
  11. LOGGER.debug("X-Forwarded-For:" + ip); 
  12.  
  13.  
  14. if (StringUtils.isBlank(ip) || "unknown".equalsIgnoreCase(ip)) { 
  15.  
  16. ip = request.getHeader("Proxy-Client-IP"); 
  17.  
  18. LOGGER.debug("Proxy-Client-IP:" + ip); 
  19.  
  20.  
  21. if (StringUtils.isBlank(ip) || "unknown".equalsIgnoreCase(ip)) { 
  22.  
  23. ip = request.getHeader("WL-Proxy-Client-IP"); 
  24.  
  25. LOGGER.debug("WL-Proxy-Client-IP:" + ip); 
  26.  
  27.  
  28. if (StringUtils.isBlank(ip) || "unknown".equalsIgnoreCase(ip)) { 
  29.  
  30. ip = request.getHeader("HTTP_CLIENT_IP"); 
  31.  
  32. LOGGER.debug("HTTP_CLIENT_IP:" + ip); 
  33.  
  34.  
  35. if (StringUtils.isBlank(ip) || "unknown".equalsIgnoreCase(ip)) { 
  36.  
  37. ip = request.getHeader("HTTP_X_FORWARDED_FOR"); 
  38.  
  39. LOGGER.debug("HTTP_X_FORWARDED_FOR:" + ip); 
  40.  
  41.  
  42. if (StringUtils.isBlank(ip) || "unknown".equalsIgnoreCase(ip)) { 
  43.  
  44. ip = request.getRemoteAddr(); 
  45.  
  46. LOGGER.debug("getRemoteAddr:" + ip); 
  47.  
  48.  
  49. return ip; 

 

你可能感兴趣的:(struts,IP)