def get_ip(request):
    """
    Extract the client IP address from the HTTP request in a
    proxy-compatible way.

    @return: IP address as a string or None if not available
    """
    if 'HTTP_X_FORWARDED_FOR' in request.environ:
        ip = request.environ['HTTP_X_FORWARDED_FOR']
    elif 'HTTP_HOST' in request.environ:
        ip = request.environ['REMOTE_ADDR']
    else:
        ip = None
    return ip
