java 获取用户真实ip
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java 获取用户真实ip相关的知识,希望对你有一定的参考价值。
/** * 获取用户真实ip * @param request * @return */ public static String getIpAddr(HttpServletRequest request){ String ip = request.getHeader("x-forwarded-for"); if ((ip == null) || (ip.length() == 0) || ("unknown".equalsIgnoreCase(ip))) { ip = request.getHeader("Proxy-Client-IP"); } if ((ip == null) || (ip.length() == 0) || ("unknown".equalsIgnoreCase(ip))) { ip = request.getHeader("WL-Proxy-Client-IP"); } if ((ip == null) || (ip.length() == 0) || ("unknown".equalsIgnoreCase(ip))) { ip = request.getRemoteAddr(); } return ip; }
以上是关于java 获取用户真实ip的主要内容,如果未能解决你的问题,请参考以下文章