郁闷中,为什么我的java代码获取客户端IP地址有错误?在线等。。。
获取客户端IP地址,我为什么有的客户获取有错误?
一个广西的客户,获取到的是广东地区的IP地址,郁闷死了。请各位高手帮帮忙。。
public String getRemoteAddress(HttpServletRequest request) {
String ip ="";
try{
ip = request.getHeader("x-forwarded-for");
if(ip == null || ip.length() == 0 || ip.equalsIgnoreCase("unknown")) ip = request.getHeader("Proxy-Client-IP");
if(ip == null || ip.length() == 0 || ip.equalsIgnoreCase("unknown")) ip = request.getHeader("WL-Proxy-Client-IP");
if(ip == null || ip.length() == 0 || ip.equalsIgnoreCase("unknown")) ip = request.getRemoteAddr();
}catch(Exception e){
//
System.err.println("get-remote-address-exception:" + e.getMessage());
}
return ip;
}