Skip to content

Instantly share code, notes, and snippets.

@jbott jbott/proxy.sh
Created May 29, 2013

Embed
What would you like to do?
Automatically create a ssh socks proxy and turn it on in network settings
#!/bin/sh
#######################################
#Remote settings
USER=USERNAME
HOST=HOSTNAME
PORT=22
#Local settings
INAME=Wi-Fi
LPORT=8080
#######################################
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root" 1>&2
exit 1
fi
echo "Starting proxy..."
ssh -ND $LPORT $USER@$HOST -p $PORT & < /dev/null
SSH_PID=$!
networksetup -setsocksfirewallproxystate $INAME on
echo "Started."
read -p "Press any key to close."
networksetup -setsocksfirewallproxystate $INAME off
kill $SSH_PID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.