Last active
June 24, 2018 15:03
-
-
Save callistabee/27529fde86592d995c2693aba4c55997 to your computer and use it in GitHub Desktop.
osx: launch and use socks proxy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
host=$1 | |
port=$2 | |
function usage() { | |
echo "usage: $(basename $0) host [port=2046]" | |
exit 1 | |
} | |
if [ $(id -u) -ne 0 ]; then | |
echo "$(basename $0): this script must be run as root" | |
usage | |
fi | |
if [ -z $host ]; then | |
usage | |
fi | |
if [ -z $port ]; then | |
port=2046 | |
fi | |
ssh -F $HOME/.ssh/config -TD $port $host & | |
sshpid=$! | |
echo "ssh running on PID $sshpid" | |
networksetup -setsocksfirewallproxy "Wi-Fi" localhost $port | |
networksetup -setsocksfirewallproxystate "Wi-Fi" on | |
function sigint() { | |
echo "caught SIGINT, terminating" | |
kill $sshpid | |
networksetup -setsocksfirewallproxystate "Wi-Fi" off | |
exit 0 | |
} | |
trap sigint SIGINT | |
wait $sshpid | |
echo "ssh died, terminating" | |
osascript -e \ | |
"display \"warning: proxy went offline\" with title \"$(basename $0)\"" | |
networksetup -setsocksfirewallproxystate "Wi-Fi" off | |
exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment