转[url]http://lidaoping12345.iteye.com/blog/1533734[/url]
获取用户的IP地址,作为防钓鱼的一种方法
String clientIp = request.getHeader("x-forwarded-for");
if ((clientIp == null) || (clientIp.length() == 0)
|| ("unknown".equalsIgnoreCase(clientIp))) {
clientIp = request.getHeader("Proxy-Client-IP");
}
if ((clientIp == null) || (clientIp.length() == 0)
|| ("unknown".equalsIgnoreCase(clientIp))) {
clientIp = request.getHeader("WL-Proxy-Client-IP");
}
if ((clientIp == null) || (clientIp.length() == 0)
|| ("unknown".equalsIgnoreCase(clientIp))) {
clientIp = request.getRemoteAddr();
}
String ipAddress = clientIp;
[b]有时候可能会根据本公司的nginx的设置,根据具体的来更改上面代码,从而获取ip地址[/b]
获取用户的IP地址,作为防钓鱼的一种方法
String clientIp = request.getHeader("x-forwarded-for");
if ((clientIp == null) || (clientIp.length() == 0)
|| ("unknown".equalsIgnoreCase(clientIp))) {
clientIp = request.getHeader("Proxy-Client-IP");
}
if ((clientIp == null) || (clientIp.length() == 0)
|| ("unknown".equalsIgnoreCase(clientIp))) {
clientIp = request.getHeader("WL-Proxy-Client-IP");
}
if ((clientIp == null) || (clientIp.length() == 0)
|| ("unknown".equalsIgnoreCase(clientIp))) {
clientIp = request.getRemoteAddr();
}
String ipAddress = clientIp;
[b]有时候可能会根据本公司的nginx的设置,根据具体的来更改上面代码,从而获取ip地址[/b]