Created
November 9, 2017 15:46
-
-
Save rpetrich/4e23d8e637b7794f4efc414246bc5196 to your computer and use it in GitHub Desktop.
Script to funnel traffic through SSH port forwarding
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 | |
if [ -z "$1" ]; then | |
echo "usage: $0 <ssh-options>" | |
exit 1 | |
fi | |
restore_network() { | |
IFS=$'\n' | |
for network in `networksetup -listallnetworkservices | grep -v '*'`; do | |
networksetup -setsocksfirewallproxystate "$network" off > /dev/null | |
done | |
exit 0 | |
} | |
if [ "$1" == --setup-network ]; then | |
IFS=$'\n' | |
for network in `networksetup -listallnetworkservices | grep -v '*'`; do | |
networksetup -setsocksfirewallproxy "$network" localhost 8157 | |
done | |
trap 'restore_network' INT | |
cat | |
fi | |
ssh -ND 8157 $@ & | |
sudo "$0" --setup-network | |
kill -SIGINT `jobs -p` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment