// 获取客户端ip public static String getClientIp(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(); } if (ip == null || ip.length() == 0 || ip.indexOf(":") > -1) { try { ip = InetAddress.getLocalHost().getHostAddress(); } catch (UnknownHostException e) { ip = null; } } return ip; }
java获取真实的客户端ip,用java后台获取ip地址
最新推荐文章于 2024-08-22 11:18:04 发布