Java获取真实IP
Java获取真实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;
}
public String getRemortIP(HttpServletRequest request) {
if (request.getHeader("x-forwarded-for" ) == null) {
return request.getRemoteAddr();
}
return request.getHeader("x-forwarded-for" );
}
» 本文链接:https://blog.apires.cn/archives/1748.html
» 转载请注明来源:Java地带
» 《Java获取真实IP》
» 本文章为Java地带整理创作,欢迎转载!转载请注明本文地址,谢谢!
» 部分内容收集整理自网络,如有侵权请联系我删除!
» 订阅本站:https://blog.apires.cn/feed/