获取客户端IP地址
/** * 获取客户端Ip地址 * @param request HttpServletRequest * @return ip addr */ private String getRemoteIP(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(); } if (ip.contains(",")) { List<String> moreIps = Arrays.stream(ip.split(",")).map(String::trim).collect(Collectors.toList()); String firstReliableIp = moreIps.stream().filter(i -> !"unknown".equalsIgnoreCase(i)).findFirst().orElse(null); if (firstReliableIp != null) { ip = firstReliableIp; } } return ip; }