[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: ExcludeNodes by country

Thanks. I've been looking for something like this.

On 7/17/06, Marcel <u-281@xxxxxxx> wrote:
Hi fellow tor users.

I made a little script to exclude the tor routers in some countries.
Either choose the countries you want, or those you don't.  You can put this
script anywhere but in your torrc directory.


# Set one or another, but not both, alphabetical order plz:
#COUNTRIES_TO_REJECT="CN|FR|GB|HK"; # Those countries will be rejected.
COUNTRIES_TO_ACCEPT="AR|BR|CA|DE|IL|JP|MX|US"; # All other countries will be rejected, those only will be accepted.

# Where to find a routers list:

# Location of your torrc file:

# Command to reload your torrc:
RELOAD="/etc/init.d/tor reload"

####  No need to modify nothing after this line ####

set -e


test -z $TORRC && exit 0

# create a backup of the torrc file
cp $TORRC ${LOCRC}.bak

# Remove ExcludeNodes line from torrc
cat $TORRC | grep -vi Excludenodes > $LOCRC

# Download routers list.
wget -O $LOCROUT $ROUTERS || exit 0

# Write list of actual countries to a text file for reference
echo -n "Countries " > $file
for i in `cat $LOCROUT | cut -f 1 -d " "| grep -v Tor | sort -u`; do
    echo -n "$i " >> $file

echo -n "ExcludeNodes " >> $file
if [ "$COUNTRIES_TO_ACCEPT" != "" ]; then
    for i in `cat $LOCROUT | egrep -v "^($COUNTRIES_TO_ACCEPT)" | cut -f 2 \
-d " " | egrep -v "^(\[|Network)" | sed s/*//`; do
        echo -n "$i, " >> $file
elif [ "$COUNTRIES_TO_REJECT" != "" ]; then
    for i in `cat $LOCROUT | egrep "^($COUNTRIES_TO_REJECT)" | cut -f 2 -d \
" " | egrep -v "^\[" | sed s/*//`; do
        echo -n "$i, " >> $file
else exit 0
echo finished >> $file


# Have Tor to reload its config