public static String getRemoteIp(HttpServletRequest request) {
String remoteAddr = request.getRemoteAddr();
String remoteIp = request.getHeader("X-Forwarded-For");
if (isBlank(remoteIp) || LOCAL_HOST_IP.equals(remoteIp)) {
remoteIp = request.getHeader("X-Real-IP");
}
if (isBlank(remoteIp) || LOCAL_HOST_IP.equals(remoteIp)) {
remoteIp = request.getHeader("Proxy-Client-IP");
}
if (isBlank(remoteIp) || LOCAL_HOST_IP.equals(remoteIp)) {
remoteIp = request.getHeader("WL-Proxy-Client-IP");
}
String ip = remoteIp != null ? remoteIp : remoteAddr;
int pos = ip.indexOf(',');
if (pos >= 0) {
ip = ip.substring(0, pos);
}
return ip;
}
```
|