java代码获取客户端的真实ip

java代码获取客户端的真实ip

protected String getIpAddr(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();
}
System.out.println("客户端ip为 :"+ip);
return ip;
}
上一篇:PHP获取客户端和服务器端IP(转)


下一篇:BZOJ Tyvj 1729 文艺平衡树