Commit f9a9c0ba authored by wei.xuan's avatar wei.xuan

feat: add custom dns support

parent eed87e45
...@@ -21,6 +21,8 @@ var ( ...@@ -21,6 +21,8 @@ var (
pprof bool pprof bool
natServer string natServer string
account string account string
dnsServer string
enableDNS bool
) )
var ( var (
...@@ -36,16 +38,10 @@ func init() { ...@@ -36,16 +38,10 @@ func init() {
flag.BoolVar(&pprof, "pprof", false, "enable pprof") flag.BoolVar(&pprof, "pprof", false, "enable pprof")
flag.StringVar(&natServer, "natServer", common.DefNatAddr, "natServer") flag.StringVar(&natServer, "natServer", common.DefNatAddr, "natServer")
flag.StringVar(&account, "account", "unknown", "account") flag.StringVar(&account, "account", "unknown", "account")
flag.StringVar(&dnsServer, "dnsServer", common.DNSServer, "custom dns server")
flag.BoolVar(&enableDNS, "enableDns", false, "enable custom dns server")
flag.Parse() flag.Parse()
// for android
net.DefaultResolver = &net.Resolver{
PreferGo: true,
Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
return net.Dial("udp", common.DNSServer)
},
}
} }
func initPprof() { func initPprof() {
...@@ -56,6 +52,16 @@ func initPprof() { ...@@ -56,6 +52,16 @@ func initPprof() {
log.Printf("enable pprof: %s", common.PprofAddr) log.Printf("enable pprof: %s", common.PprofAddr)
log.Fatal(http.ListenAndServe(common.PprofAddr, nil)) log.Fatal(http.ListenAndServe(common.PprofAddr, nil))
}() }()
// for android
if enableDNS {
net.DefaultResolver = &net.Resolver{
PreferGo: true,
Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
return net.Dial("udp", dnsServer)
},
}
}
} }
func main() { func main() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment