#!/bin/sh # Filename: block_ip.sh # Purpose: blocks all IP address/network found in a text file # The text file must have one IP address or network per line ################################################################# # Change the following path/filename to match yours IP_LIST_FILE=/path/to/ip.txt ################################################################# # Don't change anything below unless you are a smarty pant! ################################################################# IPTABLES_BIN=/sbin/iptables # Get the IP address/network from the file and ignore any line starting with # (comments) BAD_IP_ADDR_LIST=$(grep -Ev "^#" $IP_LIST_FILE) # Now loop through the IP address/network list and ban them using iptabels for i in $BAD_IP_ADDR_LIST do echo -n "Blocking $i ..."; $IPTABLES_BIN -A INPUT -s $i -j DROP $IPTABLES_BIN -A OUTPUT -d $i -j DROP echo "DONE."; done ################################################################## # END OF SCRIPT - NOTHING TO SEE HERE - THAT'S ALL FOLKS! ##################################################################