public static String getIpAddress(HttpServletRequest request) {
String ip = request.getHeader("x-forwarded-for");
if (ip == null || ip.length() == 0 || UNKNOWN_IP.equalsIgnoreCase(ip)) {
ip = request.getHeader("Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 || UNKNOWN_IP.equalsIgnoreCase(ip)) {
ip = request.getHeader("WL-Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 || UNKNOWN_IP.equalsIgnoreCase(ip)) {
ip = request.getRemoteAddr();
}
final String[] arr = ip.split(",");
for (final String str : arr) {
if (!UNKNOWN_IP.equalsIgnoreCase(str)) {
ip = str;
break;
}
}
return ip;
}
根据HttpServletRequest取ip
最新推荐文章于 2024-08-13 08:15:16 发布