在MacOSX下快速切换代理的脚本sproxy

原理是利用MacOSX中networksetup命令来设置socks5代理(Switch-proxy)

然后通过ssh方式做proxy

1
ssh  -D 7070 xxxx@xxxxx.com -p 22 -o ServerAliveInterval=30 -CN

脚本

sproxy
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/bash
host='127.0.0.1'
port='7070'
service='Wi-Fi'
ssh_server="deploy@xxxxx.com"

start_ssh

ssh_proxy_server_on(){
  ssh -D $port $ssh_server -p 22 -o ServerAliveInterval=30 -CN &
}


ssh_proxy_server_off(){
   kill -9 `lsof -n -i4TCP:7070 | grep LISTEN | awk '{print $2}' | cut -f 1 -d '/'`
}

proxy_init(){
  networksetup -setsocksfirewallproxy $service $host $port
}

proxy_on(){
  networksetup -setsocksfirewallproxystate $service on
  proxy_status
}

proxy_off(){
  networksetup -setsocksfirewallproxystate $service off
  proxy_status
}

proxy_status(){
networksetup getsocksfirewallproxy $service
}

if [ "$1" = "on" ]; then
    proxy_on
elif [ "$1" = "off" ]; then
    proxy_off
elif [ "$1" = "status" ]; then
    proxy_status
elif [ "$1" = "status" ]; then
    proxy_init
else
    printf "Usage: sproxy {init|on|off|status}\n"
fi

初始化 sproxy init

原文地址:http://dlj.bz/gQ1uKM

Comments