From 5f93aaf92f10a48ab20fb2850d69f3e635367143 Mon Sep 17 00:00:00 2001 From: xvzc Date: Tue, 4 Jan 2022 01:45:33 +0900 Subject: [PATCH] add macos proxy settings --- config/os-proxy.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 config/os-proxy.go diff --git a/config/os-proxy.go b/config/os-proxy.go new file mode 100644 index 0000000..00a5ec9 --- /dev/null +++ b/config/os-proxy.go @@ -0,0 +1,30 @@ +package config + +import ( + "os/exec" + "strings" +) + + +func SetOsProxy() error { + if GetConfig().OS != "darwin" { + 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() + if err != nil { + return err + } + + _, err = exec.Command("sh", "-c", "networksetup -setwebproxy " + strings.TrimSpace(string(network)) + " " + GetConfig().SrcIp + " " + GetConfig().SrcPort).Output() + if err != nil { + return err + } + + _, err = exec.Command("sh", "-c", "networksetup -setsecurewebproxy " + strings.TrimSpace(string(network)) + " " + GetConfig().SrcIp + " " + GetConfig().SrcPort).Output() + if err != nil { + return err + } + + return nil +}