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 (
reset
orbackup
) to restore or backupiptables
rules respectively. - Creates an
ipset
namedblockip
if it doesn't exist. - Adds
blockip
to theiptables
chainINPUT
to drop traffic from the listed IPs. - Fetches the latest IP list from the remote repository.
- Updates the
ipset
with the fetched IP addresses. - Saves the
ipset
and restartsiptables
.
- Python 3
- Rich library for enhanced console output
- Root or sudo privileges to execute
iptables
andipset
commands
To execute the script, run the Python file ban_bulk_ipset.py
. Additionally, you can use the following command-line arguments:
reset
: Restores the originaliptables
rules.backup
: Backs up the originaliptables
rules.
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.