exitnode-selector 1.05 KB
Newer Older
1 2 3 4 5 6 7
#!/bin/bash
# Shell script to change Tor exit node country

IFS=$'\n'
PS3="Chose the country: "

get_country_code() {
Lorenzo Faletra's avatar
Lorenzo Faletra committed
8
    country_data=$(grep -i "$1" /etc/anonsurf/exitnodes.csv)
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
    if [ "$country_data" ]
    then
        if [ $(echo "$country_data" | wc -l) -gt 1 ]
        then
            select country in $country_data
            do
                if [ "$country" ]
                then
                    country_data=$country
                    break
                fi
            done
        fi

        country_code=$(echo $country_data | rev | cut -d "," -f1 | rev)

    else
        echo "Could not find country."
        return 1
    fi

    echo "Country code: $country_code"
    return 0
}

change_country() {
    echo -e "authenticate \"kuhNygbtfu76fFUbgv\"\nSETCONF ExitNodes={$country_code}\nSETCONF StrictNodes=1\nsignal newnym" | nc localhost -q 1 9051
    return 0
}

if [ $# -eq 1 ]
then
    country_name=$1
else
    read -p "Country name to search: " country_name
fi

test $country_name = "all" || get_country_code $country_name && change_country