java获取客户端ip

public String getIpAddr(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.getRemoteAddr(); 
     } 
    return ip; 
   } 

 

posted @ 2018-03-30 15:24  蓝色土耳其  阅读(113)  评论(0编辑  收藏  举报