-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This provider fronts dns.google.com with www.google.com.
- Loading branch information
Showing
3 changed files
with
81 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package dnsclient | ||
|
||
import ( | ||
"encoding/json" | ||
"io/ioutil" | ||
"log" | ||
"net/http" | ||
"strconv" | ||
"time" | ||
|
||
"github.com/miekg/dns" | ||
) | ||
|
||
// GoogleFrontDNS is a Client instance resolving using Googles DNS-over-HTTPS service, | ||
// fronted using www.google.com | ||
type GoogleFrontDNS struct { | ||
BaseURL string | ||
} | ||
|
||
// Lookup performs a DNS lookup using Google | ||
func (c *GoogleFrontDNS) Lookup(name string, rType uint16) Response { | ||
|
||
client := http.Client{ | ||
Timeout: time.Second * 20, | ||
} | ||
|
||
req, err := http.NewRequest("GET", c.BaseURL, nil) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
// Update the Host client header to dns.google.com | ||
// Ref: https://twitter.com/vysecurity/status/1058947074392125440 | ||
req.Host = "dns.google.com" | ||
|
||
q := req.URL.Query() | ||
q.Add("name", name) | ||
q.Add("type", strconv.Itoa(int(rType))) | ||
q.Add("cd", "false") // ignore DNSSEC | ||
// TODO: add random_padding | ||
req.URL.RawQuery = q.Encode() | ||
|
||
res, err := client.Do(req) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
body, err := ioutil.ReadAll(res.Body) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
dnsRequestResponse := requestResponse{} | ||
err = json.Unmarshal(body, &dnsRequestResponse) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
fout := Response{} | ||
|
||
if len(dnsRequestResponse.Answer) <= 0 { | ||
return fout | ||
} | ||
|
||
fout.TTL = dnsRequestResponse.Answer[0].TTL | ||
fout.Data = dnsRequestResponse.Answer[0].Data | ||
fout.Status = dns.RcodeToString[dnsRequestResponse.Status] | ||
|
||
return fout | ||
} |