Skip to main content

基于django实现的IP访问黑名单功能。可以通过asn/network对访问IP进行拦截,禁止符合要求的IP访问网站。

Project description

django-accessblacklist

介绍

基于django实现的IP访问黑名单功能。可以通过asn/network对访问IP进行拦截,禁止符合要求的IP访问网站。

软件架构

middleware对来访ip进行筛查,判断来访IP是否在禁止名单里。 禁止名单包括 asn 和 network ,可以在后台添加。 同时可以在settings.py里定义是否启用拦截,是否启用拦截缓存,拦截缓存使用的后段以及缓存生效时间。

安装教程

  1. 确保当前应用已经部署django,
  2. pip install django-accessblacklist

使用说明

  1. 在settings.py中的INSTALLED_APPS里添加 'accessblacklist'

    eg:

    INSTALLED_APPS = [
        'django.contrib.admin',
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.messages',
        'django.contrib.staticfiles',
        'accessblacklist',
    ]
    
  2. 在settings.py的MIDDLEWARE中添加 'accessblacklist.middleware.SecureMiddleware',

    eg:

    MIDDLEWARE = [
        'accessblacklist.middleware.SecureMiddleware',
        'django.middleware.security.SecurityMiddleware',
        'django.contrib.sessions.middleware.SessionMiddleware',
        'django.middleware.common.CommonMiddleware',
        'django.middleware.csrf.CsrfViewMiddleware',
        'django.contrib.auth.middleware.AuthenticationMiddleware',
        'django.contrib.messages.middleware.MessageMiddleware',
        'django.middleware.clickjacking.XFrameOptionsMiddleware',
    ]
    
  3. 在settings.py里这是CACHE:

    eg:

        CACHES = {
            'default': {
                'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',     # 使用本地内存缓存<适用于小型项目,大型项目建议使用Redis或Memcached>
                'LOCATION': 'unique-blackiplist-cache',                         # 缓存的唯一标识符
                'TIMEOUT': 60*60*24*7,                                          # 缓存过期时间(秒) 一周
            }
        }
    
  4. 在settings.py里设置’是否启用缓存功能'和'是否启用拦截记录功能':

    IS_USE_CACHE = True  # 是否启用缓存功能,True表示启用,False表示禁用
    IS_USE_INTERCEPTIONRECORD = True  # 是否启用拦截记录功能,True表示启用,False表示禁用
    WHOIS_SERVER = "whois.arin.net" #asn查询服务器,可选值: whois.arin.net, whois.ripe.net, whois.apnic.net, whois.lacnic.net, whois.afrinic.net
    ####WHOIS_SERVER 除了第一个是经过测试的,其他的是AI补充的,使用前,需要自己测试。

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_accessblacklist-0.1.6.tar.gz (14.1 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_accessblacklist-0.1.6-py3-none-any.whl (14.1 MB view details)

Uploaded Python 3

File details

Details for the file django_accessblacklist-0.1.6.tar.gz.

File metadata

  • Download URL: django_accessblacklist-0.1.6.tar.gz
  • Upload date:
  • Size: 14.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for django_accessblacklist-0.1.6.tar.gz
Algorithm Hash digest
SHA256 c0a6300b976e2f58775d286b245d39b9b866b2e761d9450db2b7863605312379
MD5 ad98e978aea1cac4d6b2872ad9a8fc42
BLAKE2b-256 3ed5dc008cd42fdc6950936be7cd8f21b3686b25bc525b1ce24ccad4141c672c

See more details on using hashes here.

File details

Details for the file django_accessblacklist-0.1.6-py3-none-any.whl.

File metadata

File hashes

Hashes for django_accessblacklist-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 246940e16cb50b61c96712fce9e59447fec9809f19d9f90d23e432df1e247c9e
MD5 f9dade79add2c5aaa75e462a678acbef
BLAKE2b-256 d88b4327f4b9ef7abc3b10ee380342da5f6ddb3feaf82b1394cbe4a5c34c6a36

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page