Skip to content

Instantly share code, notes, and snippets.

@lvjian700
Created September 6, 2012 02:07
Show Gist options
  • Save lvjian700/3649905 to your computer and use it in GitHub Desktop.
Save lvjian700/3649905 to your computer and use it in GitHub Desktop.
Get client ip, using java
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment