Skip to content

Instantly share code, notes, and snippets.

@infoslack
Created March 20, 2014 19:52
Show Gist options
  • Save infoslack/9672383 to your computer and use it in GitHub Desktop.
Save infoslack/9672383 to your computer and use it in GitHub Desktop.
Bloqueando Botnet da China
#!/bin/sh
ISO="cn"
IPT=/sbin/iptables
WGET=/usr/bin/wget
EGREP=/bin/egrep
SPAMLIST="countrydrop"
ZONEROOT="/root/iptables"
DLROOT="http://www.ipdeny.com/ipblocks/data/countries"
[ ! -d $ZONEROOT ] && /bin/mkdir -p $ZONEROOT
$IPT -N $SPAMLIST
for c in $ISO
do
tDB=$ZONEROOT/$c.zone
$WGET -O $tDB $DLROOT/$c.zone
SPAMDROPMSG="$c Country Drop"
BADIPS=$(egrep -v "^#|^$" $tDB)
for ipblock in $BADIPS
do
$IPT -A $SPAMLIST -s $ipblock -j LOG --log-prefix "$SPAMDROPMSG"
$IPT -A $SPAMLIST -s $ipblock -j DROP
done
done
$IPT -I INPUT -j $SPAMLIST
$IPT -I OUTPUT -j $SPAMLIST
$IPT -I FORWARD -j $SPAMLIST
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment