- /**
- * 取得客户端真实ip
- *
- * @param request
- * @return 客户端真实ip
- */
- public String getIpAddr(HttpServletRequest request) {
- String ip = request.getHeader("X-Forwarded-For");
- logger.debug("1- X-Forwarded-For ip={}", ip);
- if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
- ip = request.getHeader("Proxy-Client-IP");
- logger.debug("2- Proxy-Client-IP ip={}", ip);
- }
- if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
- ip = request.getHeader("WL-Proxy-Client-IP");
- logger.debug("3- WL-Proxy-Client-IP ip={}", ip);
- }
- if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
- ip = request.getHeader("HTTP_CLIENT_IP");
- logger.debug("4- HTTP_CLIENT_IP ip={}", ip);
- }
- if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
- ip = request.getHeader("HTTP_X_FORWARDED_FOR");
- logger.debug("5- HTTP_X_FORWARDED_FOR ip={}", ip);
- }
- if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
- ip = request.getRemoteAddr();
- logger.debug("6- getRemoteAddr ip={}", ip);
- }
- logger.info("finally ip={}", ip);
- return ip;
- }
取得客户端真实ip
最新推荐文章于 2021-01-24 17:22:46 发布