Skip to content

Instantly share code, notes, and snippets.

@eclarke
Last active August 29, 2015 13:57
Show Gist options
  • Save eclarke/9773575 to your computer and use it in GitHub Desktop.
Save eclarke/9773575 to your computer and use it in GitHub Desktop.
A hackety hack function to toggle SSH/SOCKS proxy on OS X Mavericks
function toggleproxy {
# checks to see if SOCKS proxy is enabled
if [[ $(networksetup -getsocksfirewallproxy Wi-Fi | grep '^Enabled') == "Enabled: No" ]]; then
networksetup -setsocksfirewallproxystate Wi-Fi on
echo "SOCKS on!"
# checks to see if there's an existing SSH tunnel and if not, it starts one
if [[ -z $(ps aux | grep '[0-9] ssh -D 8080') ]]; then
echo -ne "Don't see a ssh tunnel on 8080 active, starting one now..."
ssh -D 8080 -f -C -q -N USERNAME@HOSTNAME.EDU # Change this from the defaults!
[[ $? == 0 ]] && echo " success!" || echo " failed :("
fi
else
networksetup -setsocksfirewallproxystate Wi-Fi off
# only show this message if there's an active SSH tunnel
if [[ -n $(ps aux | grep '[0-9] ssh -D 8080') ]]; then
echo "SOCKS off! You may want to kill your existing SSH tunnels with 'killtunnel'."
else
echo "SOCKS off!"
fi
fi
}
function maketunnel {
ssh -D 8080 -f -C -q -N USERNAME@HOSTNAME.EDU # Change this from the defaults!
}
## kills all SSH connections with port forwarding to 8080
function killtunnel {
for x in `ps -u $USER | grep -P '[0-9] ssh -D 8080' | awk '{print $2}'`; do
kill $x
done
}
@OmgImAlexis
Copy link

I'm not sure if you still use this but my fork has some fixes, mainly I added a kill command after the networksetup turns the socks proxy off and made sure that Wi-Fi and Ethernet both get the proxy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment