package sgc.portal.base.util;

import org.apache.commons.lang3.StringUtils;

import javax.servlet.http.HttpServletRequest;

public class AddressUtils {
    public static String getIpAddress(HttpServletRequest request) {
        String xForwardedFor = request.getHeader("x-forwarded-for");
        String intelSourceIP = request.getHeader("INTEL_SOURCE_IP");
        String remoteAddr = request.getRemoteAddr();

        if (StringUtils.isEmpty(xForwardedFor) || xForwardedFor.length() < 4) {
            return StringUtils.isEmpty(intelSourceIP) ? remoteAddr : intelSourceIP;
        }
        return xForwardedFor;
    }
}
