获取客户端真实IP
public static String getIpAdrress(HttpServletRequest request) {
String xip = request.getHeader("X-Real-IP");
String xFor = request.getHeader("X-Forwarded-For");
if (org.apache.commons.lang3.StringUtils.isNotEmpty(xFor) && !UNKNOWN.equalsIgnoreCase(xFor)) {
int index = xFor.indexOf(",");
if (index != -1) {
return xFor.substring(0, index);
} else {
return xFor;
}
}
xFor = xip;
if (org.apache.commons.lang3.StringUtils.isNotBlank(xFor) && !UNKNOWN.equalsIgnoreCase(xFor)) {
return xFor;
}
if (org.apache.commons.lang3.StringUtils.isBlank(xFor) || UNKNOWN.equalsIgnoreCase(xFor)) {
xFor = request.getHeader("Proxy-Client-IP");
}
if (org.apache.commons.lang3.StringUtils.isBlank(xFor) || UNKNOWN.equalsIgnoreCase(xFor)) {
xFor = request.getHeader("WL-Proxy-Client-IP");
}
if (org.apache.commons.lang3.StringUtils.isBlank(xFor) || UNKNOWN.equalsIgnoreCase(xFor)) {
xFor = request.getHeader("HTTP_CLIENT_IP");
}
if (org.apache.commons.lang3.StringUtils.isBlank(xFor) || UNKNOWN.equalsIgnoreCase(xFor)) {
xFor = request.getHeader("HTTP_X_FORWARDED_FOR");
}
if (StringUtils.isBlank(xFor) || UNKNOWN.equalsIgnoreCase(xFor)) {
xFor = request.getRemoteAddr();
}
return xFor;
}