获取请求地址的IP地址
public static String getIpAddr(HttpServletRequest request) throws Exception {
String ip = request.getHeader("X-Real-IP");
if(!StringUtils.isNullOrEmptyAfterTrim(ip) && !"unknown".equalsIgnoreCase(ip)) {
return ip;
} else {
ip = request.getHeader("X-Forwarded-For");
if(!StringUtils.isNullOrEmptyAfterTrim(ip) && !"unknown".equalsIgnoreCase(ip)) {
int index = ip.indexOf(44);
return index != -1?ip.substring(0, index):ip;
} else {
return request.getRemoteAddr();
}
}