-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstartsocksproxy.sh
More file actions
executable file
·28 lines (19 loc) · 915 Bytes
/
startsocksproxy.sh
File metadata and controls
executable file
·28 lines (19 loc) · 915 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# Script for automatic setup of SOCKS proxy through SSH connection.
# It automatically teardowns SOCKS configuration before stopping.
# It's supposed to work on Mac OS X 10.6+
#
# Author: Adam Stankiewicz (@sheerun)
#
[[ -n "$1" ]] || { echo "Usage: proxy user@example.com"; exit 1; }
# get service GUID and NAME (like Wi-Fi) to set SOCKS proxy
SERVICE_GUID=`printf "open\nget State:/Network/Global/IPv4\nd.show" | \
scutil | grep "PrimaryService" | awk '{print $3}'`
SERVICE_NAME=`printf "open\nget Setup:/Network/Service/$SERVICE_GUID\nd.show" |\
scutil | grep "UserDefinedName" | awk -F': ' '{print $2}'`
# command to disble socks proxy after at the end
finally() { sudo networksetup -setsocksfirewallproxystate "$SERVICE_NAME" off; }
# enable socks proxy in system configuration
sudo networksetup -setsocksfirewallproxy "$SERVICE_NAME" 127.0.0.1 1080 &&
ssh $1 -C -N -D 1080
trap finally INT
finally