1. public static String getIpAddr(HttpServletRequest request){
    2. if (request == null){
    3. return "unknown";
    4. }
    5. String ip = request.getHeader("x-forwarded-for");
    6. if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)){
    7. ip = request.getHeader("Proxy-Client-IP");
    8. }
    9. if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)){
    10. ip = request.getHeader("X-Forwarded-For");
    11. }
    12. if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)){
    13. ip = request.getHeader("WL-Proxy-Client-IP");
    14. }
    15. if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)){
    16. ip = request.getHeader("X-Real-IP");
    17. }
    18. if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)){
    19. ip = request.getRemoteAddr();
    20. }
    21. return "0:0:0:0:0:0:0:1".equals(ip) ? "127.0.0.1" : ip;
    22. }