This commit is contained in:
xvzc 2022-03-20 22:37:48 +09:00
parent 9143073d7c
commit d15a24a2a1

View File

@ -11,17 +11,18 @@ func SetOsProxy(port string) error {
return nil return nil
} }
network, err := exec.Command("sh", "-c", "networksetup -listnetworkserviceorder | grep `route -n get 0.0.0.0 | grep 'interface' | cut -d ':' -f2` -B 1 | head -n 1 | cut -d ' ' -f2").Output() network, err := exec.Command("sh", "-c", "networksetup -listnetworkserviceorder | grep `route -n get 0.0.0.0 | grep 'interface' | cut -d ':' -f2` -B 1 | head -n 1 | cut -d ' ' -f 2-").Output()
if err != nil { if err != nil {
return err return err
} }
_, err = exec.Command("sh", "-c", "networksetup -setwebproxy "+strings.TrimSpace(string(network))+" 127.0.0.1 "+port).Output() _, err = exec.Command("sh", "-c", "networksetup -setwebproxy "+ "'" +strings.TrimSpace(string(network)) + "'" + " 127.0.0.1 "+port).Output()
if err != nil { if err != nil {
return err return err
} }
_, err = exec.Command("sh", "-c", "networksetup -setsecurewebproxy "+strings.TrimSpace(string(network))+" 127.0.0.1 "+port).Output() _, err = exec.Command("sh", "-c", "networksetup -setsecurewebproxy " + "'" + strings.TrimSpace(string(network))+"'" + " 127.0.0.1 "+port).Output()
if err != nil { if err != nil {
return err return err
} }
@ -34,17 +35,17 @@ func UnsetOsProxy() error {
return nil return nil
} }
network, err := exec.Command("sh", "-c", "networksetup -listnetworkserviceorder | grep `route -n get 0.0.0.0 | grep 'interface' | cut -d ':' -f2` -B 1 | head -n 1 | cut -d ' ' -f2").Output() network, err := exec.Command("sh", "-c", "networksetup -listnetworkserviceorder | grep `route -n get 0.0.0.0 | grep 'interface' | cut -d ':' -f2` -B 1 | head -n 1 | cut -d ' ' -f 2-").Output()
if err != nil { if err != nil {
return err return err
} }
_, err = exec.Command("sh", "-c", "networksetup -setwebproxystate "+strings.TrimSpace(string(network))+" off").Output() _, err = exec.Command("sh", "-c", "networksetup -setwebproxystate " + "'" + strings.TrimSpace(string(network)) + "'" + " off").Output()
if err != nil { if err != nil {
return err return err
} }
_, err = exec.Command("sh", "-c", "networksetup -setsecurewebproxystate "+strings.TrimSpace(string(network))+" off").Output() _, err = exec.Command("sh", "-c", "networksetup -setsecurewebproxystate " + "'" + strings.TrimSpace(string(network)) + "'" + " off").Output()
if err != nil { if err != nil {
return err return err
} }