批量封掉危险的IP网段

根据dshield.org的黑名单,可得到一堆危险的网段,中国的IP也占了一些,我看估计都是肉鸡.
防止这些危险的机器向我们发起攻击,决定把这些危险的IP网段封掉(debian测试通过).
当然,iptables也能做,但是在大流量攻击面前,无效路由显得更轻松,不会像iptables那样占用大量资源!

  1. #!/bin/bash
  2. # filename:  block_IPs.sh
  3. # auth: baiqiuyi.com
  4. curl "http://www.spamhaus.org/drop/drop.lasso"|awk 'NR>1{print $1}' >ip
  5. if [ $? -eq 0 ];then
  6. while read ip
  7.    do
  8. /usr/bin/ipcalc $ip|sed -n '/Address/p;/Netmask/p'|sed -r 's/.*( ([0-9]{1,3}\.){3}[0-9]{1,3}).*/\1/'|sed 'N;s/\n/ netmask /g;s/^/route add -net/;s/$/ reject/'|bash
  9.    done < ip
  10.    rm -f ip
  11. exit 0
  12.  fi

附: ipcalc下载地址

2 Comments

  1. 谢谢分享。收藏了。

  2. 这个我得收藏使用下~~