Updated shorewall-blacklist.sh to removve duplicate blacklist entries

This commit is contained in:
Matthew McKinnon 2016-11-02 21:06:05 +10:00
parent 1265763dc5
commit dee8018ca2

View File

@ -4,6 +4,7 @@
# blacklist file # blacklist file
# #
BLACKLIST="/etc/shorewall/blacklist" BLACKLIST="/etc/shorewall/blacklist"
CUSTOM="/etc/shorewall/custom-blacklist"
# #
# get URL # get URL
@ -13,7 +14,7 @@ URL[0]="http://feeds.dshield.org/block.txt"
URL[1]="http://www.spamhaus.org/drop/drop.lasso" URL[1]="http://www.spamhaus.org/drop/drop.lasso"
#Counrtry BlockLists #Counrtry BlockLists
COUNTRY=(cn tw) COUNTRY=(cn tw tr mx il id)
IPDENY="http://www.ipdeny.com/ipblocks/data/countries" IPDENY="http://www.ipdeny.com/ipblocks/data/countries"
# #
@ -30,10 +31,17 @@ IPDENY="http://www.ipdeny.com/ipblocks/data/countries"
} }
trap finish EXIT trap finish EXIT
cat $BLACKLIST > "$TMP/blacklist" echo "Downloading new blacklists...."
#Blank out existing blacklists
cat /dev/null > "$TMP/blacklist"
cat /dev/null > $BLACKLIST cat /dev/null > $BLACKLIST
echo "#AUTO LIST" >> "$TMP/blacklist" #Add custom entries
if [[ -s $CUSTOM ]]; then
cat $CUSTOM >> "$TMP/blacklist"
fi
## top 20 attacking class C (/24) ## top 20 attacking class C (/24)
wget -q -O - ${URL[0]} | sed '1,/Start/d' | sed '/#/d' | awk '{print $1,$3}' | sed 's/ /\//' >> "$TMP/blacklist" wget -q -O - ${URL[0]} | sed '1,/Start/d' | sed '/#/d' | awk '{print $1,$3}' | sed 's/ /\//' >> "$TMP/blacklist"
@ -44,8 +52,8 @@ wget -q -O - ${URL[1]} | sed '1,/Expires/d' | awk '{print $1}' >> "$TMP/blackli
for BLOCK in ${COUNTRY[*]}; do for BLOCK in ${COUNTRY[*]}; do
wget -q -O - $IPDENY/$BLOCK.zone | awk '{print $1}' >> "$TMP/blacklist" wget -q -O - $IPDENY/$BLOCK.zone | awk '{print $1}' >> "$TMP/blacklist"
done done
echo "#LAST LINE -- ADD YOUR ENTRIES BEFORE THIS ONE -- DO NOT REMOVE" >> "$TMP/blacklist"
cat "$TMP/blacklist" > $BLACKLIST #Remove duplicate entries
sort "$TMP/blacklist" | uniq -c | awk '{print $2}' > $BLACKLIST
shorewall refresh &>/dev/null shorewall refresh