This script automates the process of managing IP addresses to block abusive IPs using iptables and ipset.
This Python script fetches a list of abusive IP addresses from AbuseIPDB and blocks them using iptables and ipset. It performs the following actions:
- Checks for command-line arguments (
resetorbackup) to restore or backupiptablesrules respectively. - Creates an
ipsetnamedblockipif it doesn't exist. - Adds
blockipto theiptableschainINPUTto drop traffic from the listed IPs. - Fetches the latest IP list from the remote repository.
- Updates the
ipsetwith the fetched IP addresses. - Saves the
ipsetand restartsiptables.
- Python 3
- Rich library for enhanced console output
- Root or sudo privileges to execute
iptablesandipsetcommands
To execute the script, run the Python file ban_bulk_ipset.py. Additionally, you can use the following command-line arguments:
reset: Restores the originaliptablesrules.backup: Backs up the originaliptablesrules.
Note: Exercise caution while using the reset and backup options as they modify the firewall rules.
-
Clone the repository:
git clone https://github.com/borestad/blocklist-abuseipdb.git
-
Install the required dependencies:
pip install rich
-
Execute the script:
python ban_bulk_ipset.py
Contributions and suggestions are welcome! Please fork the repository, make changes, and create a pull request.
Disclaimer: This script manages IP addresses and firewall rules. Use it responsibly and in compliance with your local laws and regulations.