diff --git a/cmd/spoof-dpi/main.go b/cmd/spoof-dpi/main.go index df0f4fb..66b90cf 100644 --- a/cmd/spoof-dpi/main.go +++ b/cmd/spoof-dpi/main.go @@ -4,6 +4,8 @@ import ( "flag" "log" "os" + "os/signal" + "syscall" "github.com/xvzc/SpoofDPI/config" "github.com/xvzc/SpoofDPI/proxy" @@ -30,5 +32,21 @@ func main() { 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) + } } diff --git a/config/os-proxy.go b/config/os-proxy.go index 0e29ce7..bfb827e 100644 --- a/config/os-proxy.go +++ b/config/os-proxy.go @@ -28,3 +28,26 @@ func SetOsProxy() error { 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 +}