[java]代码库
// 获得客户端IP
public static String getClientIP(HttpServletRequest request) {
HttpSession session = request.getSession();
// 判断是不是从代理过来的IP
String ip = request.getHeader("x-forwarded-for");
boolean blank = ip==null? true:false;
if (blank || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("Proxy-Client-IP");
}
if (blank || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("WL-Proxy-Client-IP");
}
if (blank || "unknown".equalsIgnoreCase(ip)) {
ip = request.getRemoteAddr();
}
session.setAttribute("ip", ip);
return ip;
}