1 /** 2 * 获取客户端ip地址(可以穿透代理) 3 4 * @param request 5 * @return 6 */ 7 8 @RequestMapping("getRemoteAddr") 9 public String getRemoteAddr(HttpServletRequest request) { 10 String ip = request.getHeader("X-Forwarded-For"); 11 if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 12 ip = request.getHeader("Proxy-Client-IP"); 13 } 14 if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 15 ip = request.getHeader("WL-Proxy-Client-IP"); 16 } 17 if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 18 ip = request.getHeader("HTTP_CLIENT_IP"); 19 } 20 if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 21 ip = request.getHeader("HTTP_X_FORWARDED_FOR"); 22 } 23 if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 24 ip = request.getRemoteAddr(); 25 } 26 return ip; 27 }
标签:ip,getHeader,访问者,request,equalsIgnoreCase,unknown,null,客户端 From: https://www.cnblogs.com/lwl80/p/17405541.html