Return the IP address inside the HTTP_X_FORWARDED_FOR var inside
    the `request` object.

    The return of this function can be overrided by the
    `LOCAL_GEOLOCATION_IP` variable in the `conf` module.

    This function will skip local IPs (starting with 10. and equals to
    127.0.0.1).

def get_ip(request):
    """Return the IP address inside the HTTP_X_FORWARDED_FOR var inside
    the `request` object.

    The return of this function can be overrided by the
    `LOCAL_GEOLOCATION_IP` variable in the `conf` module.

    This function will skip local IPs (starting with 10. and equals to
    127.0.0.1).
    """
    if getsetting('LOCAL_GEOLOCATION_IP'):
        return getsetting('LOCAL_GEOLOCATION_IP')

    forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')

    if not forwarded_for:
        return UNKNOWN_IP

    for ip in forwarded_for.split(','):
        ip = ip.strip()
        if not ip.startswith('10.') and not ip == '127.0.0.1':
            return ip

    return UNKNOWN_IP