Java获取客户端真实IP地址
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java获取客户端真实IP地址相关的知识,希望对你有一定的参考价值。
1 public String getIpAddr(HttpServletRequest request) { 2 String ip = request.getHeader("x-forwarded-for"); 3 if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 4 ip = request.getHeader("Proxy-Client-IP"); 5 } 6 if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 7 ip = request.getHeader("WL-Proxy-Client-IP"); 8 } 9 if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 10 ip = request.getRemoteAddr(); 11 } 12 return ip; 13 }
以上是关于Java获取客户端真实IP地址的主要内容,如果未能解决你的问题,请参考以下文章