1 /**
2 * 获取登录用户IP地址
3 *
4 * @param request
5 * @return
6 */
7 public static String getIpAddr(HttpServletRequest request) {
8 String ip = request.getHeader("x-forwarded-for");
9 if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
10 ip = request.getHeader("Proxy-Client-IP");
11 }
12 if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
13 ip = request.getHeader("WL-Proxy-Client-IP");
14 }
15 if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
16 ip = request.getRemoteAddr();
17 }
18 if (ip.equals("0:0:0:0:0:0:0:1")) {
19 ip = "本地";
20 }
21 return ip;
22 }