Last active
August 29, 2015 14:13
-
-
Save Chen-tao/9098fff8c9493d96e748 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public String getIpAddr(HttpServletRequest request) { | |
String ip = request.getHeader("x-forwarded-for"); | |
AddrLog.debug("x-forwarded-for clientIP:"+ip); | |
AddrLog.debug("remoteAddr:"+request.getRemoteAddr()); | |
if(ip !=null && !ip.equals("") && ip.length() > 0){ | |
//获取第一个ip | |
String[] ipList = ip.split(" "); | |
if(ipList.length > 0){ | |
ip = ipList[0]; | |
} | |
} | |
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment