mirror of
https://github.com/xvzc/SpoofDPI.git
synced 2024-12-22 22:36:53 +00:00
Fix dependency issues followed by refactoring util module
This commit is contained in:
parent
510f2f9835
commit
c5640a51a7
@ -4,7 +4,6 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
"runtime"
|
||||
"syscall"
|
||||
|
||||
"github.com/xvzc/SpoofDPI/doh"
|
||||
@ -15,10 +14,10 @@ import (
|
||||
func main() {
|
||||
port, dns, debug := util.ParseArgs()
|
||||
|
||||
p := proxy.New(port, runtime.GOOS, debug)
|
||||
p := proxy.New(port)
|
||||
util.PrintWelcome(port, dns, debug)
|
||||
|
||||
if err := p.SetOsProxy(); err != nil {
|
||||
if err := util.SetOsProxy(port); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
@ -44,7 +43,7 @@ func main() {
|
||||
}()
|
||||
|
||||
<-done
|
||||
if err := p.UnsetOsProxy(); err != nil {
|
||||
if err := util.UnsetOsProxy(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
@ -1,52 +0,0 @@
|
||||
package proxy
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func (p *Proxy) SetOsProxy() error {
|
||||
if p.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))+" 127.0.0.1 "+p.Port).Output()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = exec.Command("sh", "-c", "networksetup -setsecurewebproxy "+strings.TrimSpace(string(network))+" 127.0.0.1 "+p.Port).Output()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Proxy) UnsetOsProxy() error {
|
||||
if p.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
|
||||
}
|
@ -11,15 +11,11 @@ import (
|
||||
|
||||
type Proxy struct {
|
||||
Port string
|
||||
OS string
|
||||
Debug bool
|
||||
}
|
||||
|
||||
func New(port string, os string, debug bool) *Proxy {
|
||||
func New(port string) *Proxy {
|
||||
return &Proxy{
|
||||
Port: port,
|
||||
OS: os,
|
||||
Debug: debug,
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user