diff --git a/README.md b/README.md index eb4d679..9da3fb5 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,8 @@ ### Thanks - https://github.com/fardog/secureoperator -- https://github.com/jackyyf/go-shadowsocks2 +- https://github.com/shadowsocks/go-shadowsocks2 +- https://developers.cloudflare.com/1.1.1.1/dns-over-https/ - https://developers.google.com/speed/public-dns/docs/dns-over-https ### Docker diff --git a/gdns/provider_google.go b/gdns/provider_google.go index 7e6a596..4f8ae79 100644 --- a/gdns/provider_google.go +++ b/gdns/provider_google.go @@ -11,11 +11,11 @@ import ( "strings" "time" - "github.com/miekg/dns" "github.com/golang/glog" + "github.com/miekg/dns" "golang.org/x/net/proxy" - ss "github.com/jackyyf/go-shadowsocks2/proxy" + ss "github.com/chenhw2/go-shadowsocks2/proxy" ) const ( @@ -292,7 +292,7 @@ func (g GDNSProvider) Query(q DNSQuestion) (*DNSResponse, error) { return nil, err } extra := []dns.RR{} - + if q.Subnet != nil { ip, ipNet, err := net.ParseCIDR(dnsResp.EDNSClientSubnet) if err == nil { @@ -318,7 +318,6 @@ func (g GDNSProvider) Query(q DNSQuestion) (*DNSResponse, error) { } } - return &DNSResponse{ Question: dnsResp.Question.DNSQuestions(), Answer: dnsResp.Answer.DNSRRs(), diff --git a/main.go b/main.go index 9f1ab3a..0a35103 100644 --- a/main.go +++ b/main.go @@ -77,13 +77,17 @@ func main() { Usage: "Proxy (SOCKS or SHADOWSOCKS) Server for HTTP GET", }, cli.StringFlag{ - Name: "endpoint", - Value: "https://dns.google.com/resolve", - Usage: "Google DNS-over-HTTPS endpoint url", + Name: "endpoint, ep", + Value: "Google", + Usage: "Google or Cloudflare", + }, + cli.StringFlag{ + Name: "endpoint-uri, epuri", + Usage: "DNS-over-HTTPS endpoint url", }, cli.StringSliceFlag{ - Name: "endpoint-ips, eip", - Usage: "IPs of the Google DNS-over-HTTPS endpoint; if provided, endpoint lookup skip", + Name: "endpoint-ip, epip", + Usage: "IPs of the DNS-over-HTTPS endpoint; if provided, endpoint lookup skip", }, cli.StringSliceFlag{ Name: "dns-servers, d", @@ -113,7 +117,6 @@ func main() { app.Action = func(c *cli.Context) error { glogGangstaShim(c) listenAddress = c.String("listen") - gdnsEndPT = c.String("endpoint") if c.Bool("tcp") { listenProtocols = append(listenProtocols, "tcp") } @@ -134,7 +137,7 @@ func main() { gdnsOPT.Pad = !c.Bool("no-pad") gdnsOPT.Secure = !c.Bool("insecure") - for _, eip := range c.StringSlice("endpoint-ips") { + for _, eip := range c.StringSlice("endpoint-ip") { if ip := net.ParseIP(eip); ip == nil { glog.V(LERROR).Infof("%+v", fmt.Errorf("unable to parse IP from string %s", eip)) } else { @@ -152,6 +155,20 @@ func main() { } glog.V(LDEBUG).Infof("DNSServers%+v", gdnsOPT.DNSServers) + gdnsEndPT = c.String("endpoint-uri") + if 0 == len(gdnsEndPT) { + switch strings.ToUpper(c.String("endpoint")) { + default: + fallthrough + case "GOOGLE": + gdnsEndPT = `https://dns.google.com/resolve` + case "CLOUDFLARE": + gdnsEndPT = `https://cloudflare-dns.com/dns-query?ct=application/dns-json` + if 0 == len(gdnsOPT.EndpointIPs) { + gdnsOPT.EndpointIPs = []net.IP{net.ParseIP("1.1.1.1"), net.ParseIP("1.0.0.1")} + } + } + } return nil } app.Flags = append(app.Flags, glogGangstaFlags...)