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

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

然后通过ssh方式做proxy

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

脚本

```bash sproxy #!/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

Comments