content: /**
   * Copyright (c) 2010-present Abixen Systems. All rights reserved.
   *
   * This library is free software; you can redistribute it and/or modify it under
   * the terms of the GNU Lesser General Public License as published by the Free
   * Software Foundation; either version 2.1 of the License, or (at your option)
   * any later version.
   *
   * This library is distributed in the hope that it will be useful, but WITHOUT
   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
   * details.
   */
  
  package com.abixen.platform.core.application.util;
  
  import javax.servlet.http.HttpServletRequest;
  
  
  public class IpAddressUtil {
  
      private static final String[] IP_HEADERS = {
              "X-Forwarded-For",
              "Proxy-Client-IP",
              "WL-Proxy-Client-IP",
              "HTTP_X_FORWARDED_FOR",
              "HTTP_X_FORWARDED",
              "HTTP_X_CLUSTER_CLIENT_IP",
              "HTTP_CLIENT_IP",
              "HTTP_FORWARDED_FOR",
              "HTTP_FORWARDED",
              "HTTP_VIA",
              "REMOTE_ADDR"};
  
      public static String getClientIpAddress(HttpServletRequest request) {
          for (String header : IP_HEADERS) {
              String ipAddress = request.getHeader(header);
              if (ipAddress != null && ipAddress.length() != 0 && !"unknown".equalsIgnoreCase(ipAddress)) {
                  return ipAddress;
              }
          }
          return request.getRemoteAddr();
      }
  
  }