最近頻繁需要修改 Mac 的 socks 代理,每次都點進 Wi-Fi 設置裡很麻煩,有沒有那種方便設置 socks 代理的小工具小軟件?
1
1423 2023-04-08 13:15:29 +08:00
可以自己写一个,也可以借住 Raycast + 脚本
|
2
mingli 2023-04-08 13:25:35 +08:00 via iPhone
networksetup
|
3
cosmain 2023-04-08 13:49:12 +08:00
如果是浏览器,可以用 SwitchyOmega 插件
如果是命令行,可以用 export ALL_PROXY=socks5://127.0.0.1:1080 这样的方式切换 如果确实需要系统级的设置,应该有相应系统命令。 |
5
josexy 2023-04-08 15:42:33 +08:00
把下面的 shell 脚本保存到一个文件:set_proxy.sh
```shell #!/bin/bash function scutil_query { key=$1 scutil <<EOT open get $key d.show close EOT } SERVICE_GUID=$(scutil_query State:/Network/Global/IPv4 | grep "PrimaryService" | awk '{print $3}') currentservice=$(scutil_query Setup:/Network/Service/$SERVICE_GUID | grep "UserDefinedName" | awk -F': ' '{print $2}') set_proxy() { http=$1 socks=$2 if [[ -z $http ]] && [[ -z $socks ]]; then return 0 fi # http 代理 if [[ ! -z $http ]]; then networksetup -setwebproxystate "$currentservice" on networksetup -setsecurewebproxystate "$currentservice" on hostname=$(echo "$http" | awk -F ':' '{print $1}') port=$(echo "$http" | awk -F ':' '{print $2}') networksetup -setwebproxy "$currentservice" $hostname $port networksetup -setsecurewebproxy "$currentservice" $hostname $port fi # socks 代理 if [[ ! -z $socks ]]; then networksetup -setsocksfirewallproxystate "$currentservice" on hostname=$(echo "$socks" | awk -F ':' '{print $1}') port=$(echo "$socks" | awk -F ':' '{print $2}') networksetup -setsocksfirewallproxy "$currentservice" $hostname $port networksetup -setsocksfirewallproxy "$currentservice" $hostname $port fi # 设置代理绕过的域名 networksetup -setproxybypassdomains "$currentservice" 192.168.0.0/16 10.0.0.0/8 172.16.0.0/12 127.0.0.1 localhost "*.local" timestamp.apple.com } # 取消代理设置 unset_proxy() { networksetup -setwebproxy "$currentservice" "" "" off "" "" networksetup -setsecurewebproxy "$currentservice" "" "" off "" "" networksetup -setsocksfirewallproxy "$currentservice" "" "" off "" "" networksetup -setwebproxystate "$currentservice" off networksetup -setsecurewebproxystate "$currentservice" off networksetup -setsocksfirewallproxystate "$currentservice" off networksetup -setproxybypassdomains "$currentservice" Empty } if [[ $1 == "http" ]]; then set_proxy $2 "" elif [[ $1 == "socks" ]]; then set_proxy "" $2 else unset_proxy fi ``` 使用: ```shell bash set_proxy.sh http 127.0.0.1:10086 # 设置 http 和 https 代理 bash set_proxy.sh socks 127.0.0.1:10086 # 设置 socks5 代理 bash set_proxy.sh # 恢复 ``` |
6
BlackAdlerChi 2023-04-10 10:24:18 +08:00
Chromium 的浏览器+SwitchyOmega 扩展是最好的解决方案
|
7
lossfunc 2023-06-26 10:56:42 +08:00
@josephxrays 很好用,谢谢
|