Janky python script to backup/restore UFW rules and block malicous IP addresses from the Binary defence banlist and the Malcore API.
- Change line 8 of the script to reflect where you want to store the UFW backup
- Change line 71 if you want to use Malcore API (optional)
To run this script daily as root, you can set up a cron job. Here’s how you can do it:
-
Open the root user's crontab editor:
sudo crontab -e
-
Add the following line to run the script daily at a specified time (e.g., at midnight):
0 0 * * * /usr/bin/python3 /path/to/block.py
Replace /usr/bin/python3 with the path to your Python interpreter and /path/to/block_ips.py with the path to your script.
- Ensure that the script has executable permissions:
chmod +x /path/to/block.py
This setup will reset UFW rules and block the IPs from the list daily.