有这样一个需要求,公司这边做的是VIP 相当于网关,所有的主机请求,先走它然后它负责转发,而我的应该需要得到真实的主机IP地址进行限制,去网上找了一段代码如下:
public 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();
}
return ip;
}
可还是得到的VIP的那台主机的IP地址,有类似做过这样的功能的吗?求教下