Created
July 20, 2017 03:10
-
-
Save wancaibida/b03e09bfd42e7d9fce3cac73f09f510c to your computer and use it in GitHub Desktop.
Get real ip from request
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 static String getClientIP(HttpServletRequest request) | |
{ | |
String ip = request.getHeader("X-Real-IP"); | |
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) | |
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