标签:获取ip常用方法
public static String getIpAddr(HttpServletRequest request) {
final String xRealip = request.getHeader("X-Real-IP");
if (StringUtils.isNotEmpty(xRealip)) {
return xRealip;
}
final String cdnIp = request.getHeader("Cdn-Src-Ip");
if (StringUtils.isNotEmpty(cdnIp)) {
return cdnIp;
}
final String forwardIp = request.getHeader("HTTP_X_FORWARDED_FOR");
if (StringUtils.isNotEmpty(forwardIp)) {
return forwardIp;
}
final String realIp = request.getHeader("HTTP_X_REAL_IP");
if (StringUtils.isNotEmpty(realIp)) {
return realIp;
}
final String wlProxyClientIp = request.getHeader("WL-Proxy-Client-IP");
if (StringUtils.isNotEmpty(wlProxyClientIp)) {
return wlProxyClientIp;
}
final String proxyClientIp = request.getHeader("Proxy-Client-IP");
if (StringUtils.isNotEmpty(proxyClientIp)) {
return proxyClientIp;
}
return request.getRemoteAddr();
}
本文出自 “逆天” 博客,请务必保留此出处http://xxzjzsj.blog.51cto.com/3052058/1632220
标签:获取ip常用方法
原文地址:http://xxzjzsj.blog.51cto.com/3052058/1632220