Skip to content

Commit

Permalink
add Cloudflare mode
Browse files Browse the repository at this point in the history
  • Loading branch information
honwen committed May 10, 2018
1 parent 89b0e5a commit ce07cfc
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions gdns/provider_google.go
Expand Up @@ -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 (
Expand Down Expand Up @@ -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 {
Expand All @@ -318,7 +318,6 @@ func (g GDNSProvider) Query(q DNSQuestion) (*DNSResponse, error) {
}
}


return &DNSResponse{
Question: dnsResp.Question.DNSQuestions(),
Answer: dnsResp.Answer.DNSRRs(),
Expand Down
31 changes: 24 additions & 7 deletions main.go
Expand Up @@ -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",
Expand Down Expand Up @@ -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")
}
Expand All @@ -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 {
Expand All @@ -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...)
Expand Down

0 comments on commit ce07cfc

Please sign in to comment.