獲取用戶的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;
有時候可能會根據本公司的nginx的設置,根據具體的來更改上面代碼,從而獲取ip位址
創作者介紹
創作者 shadow 的頭像
shadow

資訊園

shadow 發表在 痞客邦 留言(0) 人氣()