Created
April 10, 2016 07:27
-
-
Save OmgImAlexis/8fb7c66995d05606be73e3a672bc5850 to your computer and use it in GitHub Desktop.
This file contains hidden or 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/sh | |
# | |
# To run this script from the CLI you only need to do: ./socks.sh | |
# if it's not executable, make it so: chmod +x socks.sh | |
# | |
# Change these to match your server | |
socks_host=hub | |
socks_port=8080 | |
function socks { | |
if [ "$1" = "on" ]; then | |
echo "Getting dressed" | |
# checks to see if there's an existing SSH tunnel and if not, it starts one | |
if [[ -z $(lsof -n -i :$socks_port | grep 'ssh' | awk '{print $2;}') ]]; then | |
echo "Putting my socks on" | |
sudo networksetup -setsocksfirewallproxy "Ethernet" localhost $socks_port | |
sudo networksetup -setsocksfirewallproxy "Wi-Fi" localhost $socks_port | |
ssh -C2qTnNf -D $socks_port $socks_host | |
echo "My socks are on!" | |
else | |
echo "I have socks on, I'm not putting on another pair!" | |
fi | |
elif [ $1 = "off" ]; then | |
if [[ -z $(lsof -n -i :$socks_port | grep 'ssh' | awk '{print $2;}') ]]; then | |
echo "I'm not wearing any socks?" | |
else | |
echo "Taking my socks off" | |
sudo networksetup -setsocksfirewallproxystate "Ethernet" off | |
sudo networksetup -setsocksfirewallproxystate "Wi-Fi" off | |
kill -9 $(lsof -n -i :$socks_port | grep 'ssh' | awk '{print $2;}') | |
echo "Clearnet is open!" | |
fi | |
elif [ $1 = "status" ]; then | |
if [[ -z $(lsof -n -i :$socks_port | grep 'ssh' | awk '{print $2;}') ]]; then | |
echo "My socks are off!" | |
else | |
echo "My socks are on!" | |
fi | |
else | |
echo "Huh?" | |
fi | |
} | |
# | |
# If the number of arguments are less than 1 let the idiot know! | |
# | |
if [ $# -lt 1 ]; then | |
echo "Error: I can only put socks on or take them off, wtf?" | |
exit 1 | |
fi | |
socks $@; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment