2023-12-28 09:43:45 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2023-12-28 15:36:05 -06:00
|
|
|
"go.wit.com/log"
|
2023-12-28 09:43:45 -06:00
|
|
|
"io/ioutil"
|
2023-12-28 15:36:05 -06:00
|
|
|
"encoding/json"
|
2023-12-28 09:43:45 -06:00
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
2023-12-28 15:36:05 -06:00
|
|
|
/*
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2023-12-28 09:43:45 -06:00
|
|
|
// dnsLookupDoH performs a DNS lookup for AAAA records over HTTPS.
|
2023-12-28 15:36:05 -06:00
|
|
|
func dnsAAAAlookupDoH(domain string) ([]string, error) {
|
2023-12-28 09:43:45 -06:00
|
|
|
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)
|
|
|
|
|
2023-12-28 15:36:05 -06:00
|
|
|
log.Println("curl", url)
|
|
|
|
|
2023-12-28 09:43:45 -06:00
|
|
|
// 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
|
|
|
|
}
|
2023-12-29 01:36:10 -06:00
|
|
|
|
|
|
|
// 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)
|
|
|
|
|
|
|
|
log.Println("curl", url)
|
|
|
|
|
|
|
|
// Perform the HTTP GET request
|
|
|
|
resp, err := http.Get(url)
|
|
|
|
if err != nil {
|
|
|
|
log.Error(err, "error performing DNS-over-HTTPS request")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
// Read and unmarshal the response body
|
|
|
|
body, err := ioutil.ReadAll(resp.Body)
|
|
|
|
if err != nil {
|
|
|
|
log.Error(fmt.Errorf("error reading response: %w", err))
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var data struct {
|
|
|
|
Answer []struct {
|
|
|
|
Data string `json:"data"`
|
|
|
|
} `json:"Answer"`
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := json.Unmarshal(body, &data); err != nil {
|
|
|
|
log.Error(fmt.Errorf("error unmarshaling response: %w", err))
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Extract the IPv6 addresses
|
|
|
|
for _, answer := range data.Answer {
|
|
|
|
values = append(values, answer.Data)
|
|
|
|
}
|
|
|
|
|
|
|
|
return values
|
|
|
|
}
|