root@raspbx:~# cat voipbl.sh
#download and set up iptables first time
if [ ! -f /root/block.ip ]
then
wget -qO - http://www.voipbl.org/update/ | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3 \}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\/[0-9]\{1,2\}' | grep -Ev "192.168" > /root/block .ip
cat /root/block.ip | awk '{print "iptables -A INPUT -s "$1" -j DROP"}' | sh
else
#Download, clear unwanted and create backup
wget -qO - http://www.voipbl.org/update/ | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\. [0-9]\{1,3\}\.[0-9]\{1,3\}\/[0-9]\{1,2\}' | grep -Ev "192.168" > /root/blockN.ip
#compare diff
#add new record to iptables
diff /root/block.ip /root/blockN.ip | grep ">" | awk '{print "/sbin/iptables -A INPUT -s "$2" -j DROP"}' | sh
#remove old record from iptables
diff /root/block.ip /root/blockN.ip | grep "<" | awk '{print "/sbin/iptables -D INPUT -s "$2" -j DROP"}' | sh
#email diff
(wc -l /root/blockN.ip;diff /root/block.ip /root/blockN.ip | grep '>\|<')| mail -s "VoIP BL Update" xxxxx@gmail.com
#update files
rm -f /root/block1.ip
mv /root/block.ip /root/block1.ip
mv /root/blockN.ip /root/block.ip
fi |