SpoofDPI/cmd/spoof-dpi/main.go

60 lines
869 B
Go
Raw Normal View History

2021-12-28 02:28:43 +00:00
package main
import (
2021-12-29 17:08:30 +00:00
"flag"
2022-01-03 16:46:16 +00:00
"log"
2021-12-29 17:08:30 +00:00
"os"
2022-01-04 08:38:36 +00:00
"os/signal"
"syscall"
2021-12-28 06:10:06 +00:00
2022-01-03 07:24:39 +00:00
"github.com/xvzc/SpoofDPI/config"
2022-01-03 15:13:42 +00:00
"github.com/xvzc/SpoofDPI/proxy"
2022-01-04 08:38:36 +00:00
"github.com/xvzc/SpoofDPI/util"
2021-12-28 02:28:43 +00:00
)
func main() {
2022-01-04 08:38:36 +00:00
port := flag.String("port", "8080", "port")
dns := flag.String("dns", "8.8.8.8", "DNS server")
debug := flag.Bool("debug", false, "true | false")
2022-01-03 15:30:15 +00:00
2022-01-04 08:38:36 +00:00
flag.Parse()
2021-12-29 17:08:30 +00:00
2022-01-04 08:38:36 +00:00
err := config.InitConfig(*port, *dns, *debug)
if err != nil {
os.Exit(1)
}
2021-12-29 17:08:30 +00:00
2022-01-04 08:38:36 +00:00
util.PrintWelcome()
2022-01-03 15:13:42 +00:00
2022-01-04 08:38:36 +00:00
err = config.SetOsProxy()
if err != nil {
log.Fatal(err)
os.Exit(1)
}
2022-01-03 15:13:42 +00:00
2022-01-04 08:38:36 +00:00
go proxy.Start()
2022-01-03 17:36:27 +00:00
2022-01-04 08:38:36 +00:00
sigs := make(chan os.Signal, 1)
2022-01-03 17:36:27 +00:00
done := make(chan bool, 1)
2022-01-04 08:38:36 +00:00
signal.Notify(
sigs,
syscall.SIGKILL,
syscall.SIGINT,
syscall.SIGTERM,
syscall.SIGQUIT,
syscall.SIGHUP)
go func() {
2022-01-03 17:36:27 +00:00
_ = <-sigs
done <- true
}()
2022-01-04 08:38:36 +00:00
<-done
err = config.UnSetOsProxy()
if err != nil {
log.Fatal(err)
os.Exit(1)
}
2021-12-28 02:28:43 +00:00
}