Skip to content

Instantly share code, notes, and snippets.

@elementalvoid
Created December 1, 2015 16:22
Show Gist options
  • Save elementalvoid/4028d0f3e4435e089ecd to your computer and use it in GitHub Desktop.
Save elementalvoid/4028d0f3e4435e089ecd to your computer and use it in GitHub Desktop.
Run firefox configured for a SSH Socks proxy connection that's managed by the script.
#!/bin/bash
if [[ $# -lt 1 ]]; then
echo "usage: $(basename ${0}) <gateway>"
exit 1
fi
gateway=${1}
shift
ssh_pid=-1
cleanup () {
kill ${ssh_pid}
}
trap cleanup SIGKILL SIGQUIT
# Find an open port
port=
ports_in_use=$(netstat -lnt 2>&1 | grep tcp | grep -v tcp6 | awk '{print $4}' | awk -F: '{print $2}' | xargs echo -n)
while (true)
do
port=$(($RANDOM+2000)) #random port between 2000 and 32767+2000
if ! [[ "${ports_in_use}" =~ "${port}" ]]
then
break
fi
done
ssh -N -D${port} ${gateway} &
ssh_pid=$!
sed -i -e "s/\"network.proxy.socks_port\", [0-9]*/\"network.proxy.socks_port\", $port/" ~/.mozilla/firefox/*.socks/prefs.js
firefox -P socks $@
cleanup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment