public String getIP(HttpServletRequest request) {
String ip = request.getHeader("x-forwarded-for");
if (null == ip || 0 == ip.length() || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("Proxy-Client-IP");
}
if (null == ip || 0 == ip.length() || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("WL-Proxy-Client-IP");
}
if (null == ip || 0 == ip.length() || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("X-Real-IP");
}
if (null == ip || 0 == ip.length() || "unknown".equalsIgnoreCase(ip)) {
ip = request.getRemoteAddr();
}
return ip;
}
java获取当前请求的ip
最新推荐文章于 2024-07-13 02:44:21 发布