java 后台获取访问客户端ip地址

  1. protected String getClientIpAddress(HttpServletRequest request) {  
  2.         String clientIp = request.getHeader("x-forwarded-for");  
  3.         if(clientIp == null || clientIp.length() == 0 || "unknown".equalsIgnoreCase(clientIp)) {  
  4.             clientIp = request.getHeader("Proxy-Client-IP");  
  5.         }  
  6.         if(clientIp == null || clientIp.length() == 0 || "unknown".equalsIgnoreCase(clientIp)) {  
  7.             clientIp = request.getHeader("WL-Proxy-Client-IP");  
  8.         }  
  9.         if(clientIp == null || clientIp.length() == 0 || "unknown".equalsIgnoreCase(clientIp)) {  
  10.             clientIp = request.getRemoteAddr();  
  11.         }  
  12.         return clientIp;  
  13.     }  

你可能感兴趣的:(java)