-
-
Save baseboxorg/bd41c1fc65718071e72b to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
# auto start ssh proxy under mac osx, need to sshpass support | |
# goto http://sourceforge.net/projects/sshpass/ download http://nchc.dl.sourceforge.net/project/sshpass/sshpass/1.05/sshpass-1.05.tar.gz | |
# cd ~/Downloads | |
# tar -zxvf sshpass-1.05.tar.gz | |
# cd sshpass-1.05 | |
# ./configure | |
# make | |
# sudo make install | |
# done | |
SSH_USER=<your ssh username> | |
SSH_PASS=<your ssh pass> | |
SSH_PORT=22 | |
SSH_HOST=<your ssh host> | |
SSH_FORWARD=<the proxy port you want to use, the same in your pac file> | |
#run `networksetup listallnetworkservices` to get available network service names | |
SERVICE="Wi-Fi" | |
#use a server to serve the pac file is better than static file | |
PAC_URL="http://127.0.0.1:8080/gfw.pac" | |
#do not use proxy when close this script | |
on_die() { | |
echo | |
echo proxy off | |
echo | |
sudo networksetup -setautoproxystate ${SERVICE} off | |
} | |
trap "on_die" SIGTERM | |
trap "on_die" SIGINT | |
trap "on_die" SIGHUP | |
#when start this script, start the proxy | |
sudo networksetup -setautoproxystate ${SERVICE} off | |
sudo networksetup -setautoproxyurl ${SERVICE} ${PAC_URL} | |
sudo networksetup -setautoproxystate ${SERVICE} on | |
echo | |
echo now connect to the ssh server... | |
echo | |
sshpass -p ${SSH_USER} ssh -o StrictHostKeyChecking=no -N -D ${SSH_FORWARD} ${SSH_USER}@${SSH_HOST} -p ${SSH_PORT} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment