Coder Social home page Coder Social logo

autoblockiplist's Introduction

AutoBlockIPList

This script allows you to automate the update of the IP block list on the Synology NAS from a list of IP's (custom user or external list).

This script was tested with Synology DSM 6 (6.2.4) and 7 (7.0, 7.1 and 7.2)

⚠️ After Synology update, if you encounter any issue, re-run install requirements

Table of contents

Usage

AutoBlockIPList [-h] [-f [IN_FILE ...]] [-u [IN_URL ...]]
                       [-e EXPIRE_IN_DAY] [--remove-expired] [-b BACKUP_TO]
                       [--clear-db] [--dry-run] [-v] [--version]

optional arguments:

-h, --help            show this help message and exit

-f [IN_FILE ...], --in-file [IN_FILE ...]
                    Local list file separated by a space (eg.
                    /home/user/list.txt custom.txt)
                    
-u [IN_URL ...], --in-url [IN_URL ...]
                    External list url separated by a space (eg
                    https://example.com/list.txt
                    https://example.com/all.txt)
                    
-e EXPIRE_IN_DAY, --expire-in-day EXPIRE_IN_DAY
                    Expire time in day. Default 0: no expiration
                    
--remove-expired      Remove expired entry

-b BACKUP_TO, --backup-to BACKUP_TO
                    Folder to store a backup of the database
                    
--clear-db            Clear ALL deny entry in database before filling

--dry-run             Perform a run without any modifications

-v, --verbose         Increase output verbosity

--version             show program's version number and exit

Installation

Download latest release and unzip contents.

From command line though SSH:

wget https://github.com/kichetof/AutoBlockIPList/releases/latest/download/AutoBlockIPList.zip
7z x AutoBlockIPList.zip

Requirements

In DSM, install package python3.

Connect to your NAS though SSH and execute following commands:

sudo python3 -m ensurepip

Go to AutoBlockIPList folder and run

sudo python3 -m pip install -r requirements.txt


First use

Before to run this script in your schedule tasks, perform some single run in SSH.

First one with --backup-to and --dry-run to get a backup of your database.

Next with --in-file or --in-url and --dry-run.


Synology DSM

Manual usage (recommended for first use)
  • Connect to your NAS though SSH
  • execute script like: sudo python3 /volume1/scripts/AutoBlockIPList.py -v --dry-run --backup-to . --in-file /volume1/homes/user/custom.txt
Schedule task
  • Go to Control Panel -> Task scheduler Task scheduler
  • Setting up the task as "root" user Task settings

Enjoy 😎

autoblockiplist's People

Contributors

kichetof avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

autoblockiplist's Issues

Stopped working after updating to 7.2.x

The script produces the following errors after updating to 7.2.x (reinstallation of requirements.txt was done after the update)

_Traceback (most recent call last):
File "/volume1/Backup/IMAGES/DS/Blocklist/AutoBlockIPList.py", line 136, in
args = parse_args()
File "/volume1/Backup/IMAGES/DS/Blocklist/AutoBlockIPList.py", line 122, in parse_args
a = parser.parse_args()
File "/usr/lib/python3.8/argparse.py", line 1768, in parse_args
args, argv = self.parse_known_args(args, namespace)
File "/usr/lib/python3.8/argparse.py", line 1800, in parse_known_args
namespace, args = self._parse_known_args(args, namespace)
File "/usr/lib/python3.8/argparse.py", line 2006, in _parse_known_args
start_index = consume_optional(start_index)
File "/usr/lib/python3.8/argparse.py", line 1946, in consume_optional
take_action(action, args, option_string)
File "/usr/lib/python3.8/argparse.py", line 1858, in take_action
argument_values = self._get_values(action, argument_strings)
File "/usr/lib/python3.8/argparse.py", line 2407, in _get_values
value = [self._get_value(action, v) for v in arg_strings]
File "/usr/lib/python3.8/argparse.py", line 2407, in
value = [self._get_value(action, v) for v in arg_strings]
File "/usr/lib/python3.8/argparse.py", line 2422, in get_value
result = type_func(arg_string)
File "/volume1/Backup/IMAGES/DS/Blocklist/AutoBlockIPList.py", line 76, in url
if isinstance(validator, validators.ValidationFailure):
AttributeError: module 'validators' has no attribute 'ValidationFailure'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.