Block an entire Country with iptables

Started by FooKaS, December 03, 2014, 10:00:07 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Tundracanine

you could try changing
[ ! -d $ZONEROOT ] && /bin/mkdir -p $ZONEROOT
to
[ ! -d $ZONEROOT ] && /bin/mkdir -p $ZONEROOT
i tried the ones listed on the other pages from like git and even those did not work..

ah i see that forum phased wrong lol
http://www.cyberciti.biz/faq/block-entier-country-using-iptables/
If wanting support help please put bare min info like
Os:
U-232 Version:
Php Version:
Tracker type: like xbt or php
Saves on asking more questions just so people can help someone.

FooKaS

Has nothing to do with u232 ifself but i wanted to do it but having an error.Here is the code

#!/bin/bash
### Block all traffic from AFGHANISTAN (af) and CHINA (CN). Use ISO code ###
ISO="af cn"

### Set PATH ###
IPT=/sbin/iptables
WGET=/usr/bin/wget
EGREP=/bin/egrep

### No editing below ###
SPAMLIST="countrydrop"
ZONEROOT="/root/iptables"
DLROOT="http://www.ipdeny.com/ipblocks/data/countries"

cleanOldRules(){
$IPT -F
$IPT -X
$IPT -t nat -F
$IPT -t nat -X
$IPT -t mangle -F
$IPT -t mangle -X
$IPT -P INPUT ACCEPT
$IPT -P OUTPUT ACCEPT
$IPT -P FORWARD ACCEPT
}

# create a dir
[ ! -d $ZONEROOT ] && /bin/mkdir -p $ZONEROOT

# clean old rules
cleanOldRules

# create a new iptables list
$IPT -N $SPAMLIST

for c  in $ISO
do
# local zone file
tDB=$ZONEROOT/$c.zone

# get fresh zone file
$WGET -O $tDB $DLROOT/$c.zone

# country specific log message
SPAMDROPMSG="$c Country Drop"

# get
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

# Drop everything
$IPT -I INPUT -j $SPAMLIST
$IPT -I OUTPUT -j $SPAMLIST
$IPT -I FORWARD -j $SPAMLIST

# call your other iptable script
# /path/to/other/iptables.sh

exit 0


Save above script as root user to "country.block.iptables.sh" and change the ISO variable to match the country name using ISO country codes.I do that and when i run it i an getting this

./country.block.iptables.sh
./country.block.iptables.sh: line 28: syntax error near unexpected token `;&'
./country.block.iptables.sh: line 28: `[ ! -d $ZONEROOT ] && /bin/mkdir -p $ZONEROOT'

Anyone try/do this before? here is the link to the page i got this from 
http://www.lowendguide.com/3/networking/block-an-entire-country-with-iptables-2/
DA TAXMAN