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表示禁用

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.3.tar.gz (7.0 kB 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.3-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_accessblacklist-0.1.3.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • 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.3.tar.gz
Algorithm Hash digest
SHA256 9bf690262fb0f7e7532c71c6c73098c5f7ea73eec2e151f356109bb115824552
MD5 d590ff5b076eb4451d948ffcce6cb042
BLAKE2b-256 4d65e6cfa66fe3da46a9b62eb97731b6216ed9f8a3097b392a6d656ce38013c5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_accessblacklist-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c68325f4d5f719ef4bc2f19406b98831d44d2fb417a3977319c8c11cffdda803
MD5 28a039e27a661e14c0cefc5c14f5c5de
BLAKE2b-256 bb372ac48d2d1de34c5c8df678c7c00fd8ff3a7acf2f02e9e98f39984a107ad7

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