Advertisement
Guest User

Country banned

a guest
Sep 23rd, 2014
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.38 KB | None | 0 0
  1. #!/bin/bash
  2. # Purpose: Block all traffic from AFGHANISTAN (af) and CHINA (cn). Use ISO code. #
  3. # See url for more info - http://www.cyberciti.biz/faq/?p=3402
  4. # Author: nixCraft <www.cyberciti.biz> under GPL v.2.0+
  5. # -------------------------------------------------------------------------------
  6. ISO="vn cn"
  7. ### Set PATH ###
  8. IPT=/sbin/iptables
  9. WGET=/usr/bin/wget
  10. EGREP=/bin/egrep
  11. ### No editing below ###
  12. SPAMLIST="countrydrop"
  13. ZONEROOT="/root/iptables"
  14. DLROOT="http://www.ipdeny.com/ipblocks/data/countries"
  15. cleanOldRules(){
  16. $IPT -F
  17. $IPT -X
  18. $IPT -t nat -F
  19. $IPT -t nat -X
  20. $IPT -t mangle -F
  21. $IPT -t mangle -X
  22. $IPT -P INPUT ACCEPT
  23. $IPT -P OUTPUT ACCEPT
  24. $IPT -P FORWARD ACCEPT
  25. }
  26. # create a dir
  27. [ ! -d $ZONEROOT ] && /bin/mkdir -p $ZONEROOT
  28. # clean old rules
  29. cleanOldRules
  30. # create a new iptables list
  31. $IPT -N $SPAMLIST
  32. for c  in $ISO
  33. do
  34.     # local zone file
  35.     tDB=$ZONEROOT/$c.zone
  36.     # get fresh zone file
  37.     $WGET -O $tDB $DLROOT/$c.zone
  38.     # country specific log message
  39.     SPAMDROPMSG="$c Country Drop"
  40.     # get
  41.     BADIPS=$(egrep -v "^#|^$" $tDB)
  42.     for ipblock in $BADIPS
  43.     do
  44.        $IPT -A $SPAMLIST -s $ipblock -j LOG --log-prefix "$SPAMDROPMSG"
  45.        $IPT -A $SPAMLIST -s $ipblock -j DROP
  46.     done
  47. done
  48. # Drop everything
  49. $IPT -I INPUT -j $SPAMLIST
  50. $IPT -I OUTPUT -j $SPAMLIST
  51. $IPT -I FORWARD -j $SPAMLIST
  52. # call your other iptable script
  53. # /path/to/other/iptables.sh
  54. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement