Block IP addresses

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
"""
simple middlware to block IP addresses via settings variable BLOCKED_IPS
"""
from django.conf import settings
from django import http

class BlockedIpMiddleware(object):

    def process_request(self, request):
        if request.META['REMOTE_ADDR'] in settings.BLOCKED_IPS:
            return http.HttpResponseForbidden('<h1>Forbidden</h1>')
        return None

More like this

  1. Firebug Lite Middleware by jfw 3 years, 3 months ago
  2. User/IP Banning Middleware by justquick 3 years, 9 months ago
  3. Mobilize your Django site by stevena0 2 years, 10 months ago
  4. Globs for INTERNAL_IPS by kcarnold 2 years, 10 months ago
  5. Remove self links middleware by svetlyak 3 years, 10 months ago

Comments

(Forgotten your password?)