wiki:doc/MultipleTorBrowsers

Bash script to create multiple torbrowsers with different IPs given a folder with the default TorBrowser.

Code highlighting:

#!/bin/bash

usage() { echo "Usage: $0 [-n <number of copies>] [-p <path to default TBB>]" 1>&2; exit 1; }

print_userjs(){
  local socksport=${1}
  local controlport=${2}
  local dest=${3}
  echo "user_pref(\"extensions.torlauncher.control_port\",$controlport);" > $dest
  echo "user_pref(\"extensions.torbutton.custom.socks_port\",$socksport);" >> $dest
  echo "user_pref(\"extensions.torbutton.custom.socks_host\",\"127.0.0.1\");" >> $dest
  echo "user_pref(\"extensions.torbutton.proxies_applied\",false);" >> $dest
  echo "user_pref(\"extensions.torbutton.use_privoxy\",false);" >> $dest
  echo "user_pref(\"network.proxy.socks_port\",$socksport);" >> $dest
}

while getopts ":n:p:" o; do
  case "${o}" in
    n)
      n=${OPTARG}
      ;;
    p)
      p=${OPTARG}
      ;;
    *)
      usage
      exit 0
     ;;
  esac
done
if [ -z "$n" ] || [ -z "$p" ];
then
  usage
  exit 0
fi
for i in `seq 1 $n`;
do
  CONTROL_PORT=$((9151+$i*2))
  SOCKS_PORT=$((9150+$i*2)) 
  echo "$i) Copying $p to TBB$i"
  cp -r $p TBB$i
  echo "$i) Creating user.js with SocksPort $SOCKS_PORT and ControlPort $CONTROL_PORT"
  print_userjs $SOCKS_PORT $CONTROL_PORT "./TBB$i/Browser/TorBrowser/Data/Browser/profile.default/user.js"
  echo "$i) Modifying torrc-default"
  TORRC="./TBB$i/Browser/TorBrowser/Data/Tor/torrc-defaults"
  sed -i "s/SocksPort 9150/SocksPort $SOCKS_PORT/g" $TORRC 
  sed -i "s/ControlPort 9151/ControlPort $CONTROL_PORT/g" $TORRC
done
Last modified 3 years ago Last modified on Jun 6, 2015, 9:39:43 PM