Java获取客户端真实IP地址
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 public String getIpAddr(HttpServletRequest request) { 2 String ip = request.getHeader("x-forwarded-for"); 3 if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 4 ip = request.getHeader("Proxy-Client-IP"); 5 } 6 if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 7 ip = request.getHeader("WL-Proxy-Client-IP"); 8 } 9 if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 10 ip = request.getRemoteAddr(); 11 } 12 return ip; 13 }