Get Client IP Behind Proxy

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
def get_ip(request):
    """Returns the IP of the request, accounting for the possibility of being
    behind a proxy.
    """
    ip = request.META.get("HTTP_X_FORWARDED_FOR", None)
    if ip:
        # X_FORWARDED_FOR returns client1, proxy1, proxy2,...
        ip = ip.split(", ")[0]
    else:
        ip = request.META.get("REMOTE_ADDR", "")
    return ip

More like this

  1. Add get_addr() method to request object by nikmolnar 5 months, 1 week ago
  2. Effective content caching for mass-load site using redirect feature by nnseva 1 year, 10 months ago
  3. Single Django App behind multiple Apache Proxies by chadmaine 6 years ago
  4. Enable AWS ELB with SSL Termination by zvikico 1 year, 11 months ago
  5. Semi-Portable recaptcha integration with django forms by pinkeen 2 years, 5 months ago

Comments

(Forgotten your password?)