add unset os-proxy

This commit is contained in:
xvzc 2022-01-04 02:36:27 +09:00
parent b8f614d808
commit cf869fe9cd
2 changed files with 42 additions and 1 deletions

View File

@ -4,6 +4,8 @@ import (
"flag" "flag"
"log" "log"
"os" "os"
"os/signal"
"syscall"
"github.com/xvzc/SpoofDPI/config" "github.com/xvzc/SpoofDPI/config"
"github.com/xvzc/SpoofDPI/proxy" "github.com/xvzc/SpoofDPI/proxy"
@ -30,5 +32,21 @@ func main() {
os.Exit(1) os.Exit(1)
} }
proxy.Start() go proxy.Start()
sigs := make(chan os.Signal, 1)
done := make(chan bool, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
go func() {
_ = <-sigs
done <- true
}()
<-done
err = config.UnSetOsProxy()
if err != nil {
log.Fatal(err)
os.Exit(1)
}
} }

View File

@ -28,3 +28,26 @@ func SetOsProxy() error {
return nil return nil
} }
func UnSetOsProxy() (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 -setwebproxystate " + strings.TrimSpace(string(network)) + " off").Output()
if err != nil {
return err
}
_, err = exec.Command("sh", "-c", "networksetup -setsecurewebproxystate " + strings.TrimSpace(string(network)) + " off").Output()
if err != nil {
return err
}
return nil
}