/**
* 获得客户端IP地址.
*
* @param request
* the http servlet request
* @return 返回ip地址
*/
public static String getRemoteAddr(HttpServletRequest request) {
String addr = request.getHeader("x-forwarded-for");
if (StringUtils.isEmpty(addr) || "unknown".equalsIgnoreCase(addr)) {
addr = request.getHeader("proxy-client-ip");
}
if (StringUtils.isEmpty(addr) || "unknown".equalsIgnoreCase(addr)) {
addr = request.getHeader("wl-proxy-client-ip");
}
if (!StringUtils.isEmpty(addr)) {
addr = addr.replaceAll("unknown,?", "").trim().replaceAll(",.*", "");
} else {
addr = request.getRemoteAddr();
}
if (StringUtils.isNotBlank(addr)) {
addr = Jsoup.clean(addr, Whitelist.none());
}
return addr;
}
获得客户端IP地址
最新推荐文章于 2024-09-01 15:30:33 发布