获取当前电脑的ip地址
String client_ip = request.getHeader("x-forwarded-for"); if(client_ip == null || client_ip.length() == 0 || "unknown".equalsIgnoreCase(client_ip)) { client_ip = request.getHeader("Proxy-Client-IP"); } if(client_ip == null || client_ip.length() == 0 || "unknown".equalsIgnoreCase(client_ip)) { client_ip = request.getHeader("WL-Proxy-Client-IP"); } if(client_ip == null || client_ip.length() == 0 || "unknown".equalsIgnoreCase(client_ip)) { client_ip = request.getRemoteAddr(); } //对于通过多个代理的情况,第一个IP为客户端真实IP,多个IP按照','分割 if(client_ip != null && client_ip.length() > 15){ //"***.***.***.***".length() = 15 if(client_ip.indexOf(",") > 0){ client_ip = client_ip.substring(0,client_ip.indexOf(",")); } }