summaryrefslogtreecommitdiff
path: root/dns-https.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-01-06 01:41:33 -0600
committerJeff Carr <[email protected]>2024-01-06 01:41:33 -0600
commitca3a01f478aa60fb039892d2cae6823188b5842c (patch)
tree55e13fa31e58b6d1bdb1fc298200ccc458a9df5c /dns-https.go
parent2d1e3213261bee4640c11d8e1f526fcb6234e037 (diff)
make new resolverStatus()
also fix dns-https Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'dns-https.go')
-rw-r--r--dns-https.go64
1 files changed, 6 insertions, 58 deletions
diff --git a/dns-https.go b/dns-https.go
index 6579903..bd06d4c 100644
--- a/dns-https.go
+++ b/dns-https.go
@@ -8,70 +8,18 @@ import (
"net/http"
)
-/*
-func getAAAArecords() {
- hostname := "go.wit.com"
- ipv6Addresses, err := dnsLookupDoH(hostname)
- if err != nil {
- log.Error(err, "getAAAArecords")
- return
- }
-
- fmt.Printf("IPv6 Addresses for %s:\n", hostname)
- for _, addr := range ipv6Addresses {
- log.Println(addr)
- }
-}
-*/
-
-// dnsLookupDoH performs a DNS lookup for AAAA records over HTTPS.
-func dnsAAAAlookupDoH(domain string) ([]string, error) {
- var ipv6Addresses []string
-
- // Construct the URL for a DNS query with Google's DNS-over-HTTPS API
- url := fmt.Sprintf("https://dns.google/resolve?name=%s&type=AAAA", domain)
-
- log.Println("curl", url)
-
- // Perform the HTTP GET request
- resp, err := http.Get(url)
- if err != nil {
- return nil, fmt.Errorf("error performing DNS-over-HTTPS request: %w", err)
- }
- defer resp.Body.Close()
-
- // Read and unmarshal the response body
- body, err := ioutil.ReadAll(resp.Body)
- if err != nil {
- return nil, fmt.Errorf("error reading response: %w", err)
- }
-
- var data struct {
- Answer []struct {
- Data string `json:"data"`
- } `json:"Answer"`
- }
-
- if err := json.Unmarshal(body, &data); err != nil {
- return nil, fmt.Errorf("error unmarshaling response: %w", err)
- }
-
- // Extract the IPv6 addresses
- for _, answer := range data.Answer {
- ipv6Addresses = append(ipv6Addresses, answer.Data)
- }
-
- return ipv6Addresses, nil
-}
-
// dnsLookupDoH performs a DNS lookup for AAAA records over HTTPS.
func lookupDoH(hostname string, rrType string) []string {
var values []string
// Construct the URL for a DNS query with Google's DNS-over-HTTPS API
- url := fmt.Sprintf("https://dns.google/resolve?name=%s&type=%s", hostname, rrType)
+ url := fmt.Sprintf("https://dns.google.com/resolve?name=%s&type=%s", hostname, rrType)
- log.Println("curl", url)
+ log.Log(DNS, "lookupDoH()", url)
+ if hostname == "" {
+ log.Warn("lookupDoH() was sent a empty hostname")
+ return nil
+ }
// Perform the HTTP GET request
resp, err := http.Get(url)