hehe off-by-one
All checks were successful
continuous-integration/drone/push Build is passing

Signed-off-by: Sam Therapy <sam@samtherapy.net>
This commit is contained in:
Sam Therapy 2022-06-23 23:18:54 +02:00
parent bf06f7a3aa
commit db78235ecd
Signed by: sam
GPG key ID: 4D8B07C18F31ACBD
2 changed files with 1 additions and 48 deletions

2
cli.go
View file

@ -186,7 +186,7 @@ func parseArgs(args []string) (util.Answers, error) {
// TODO: Actually find where windows stuffs its dns resolvers
resp.Answers.Server = "8.8.4.4"
} else {
resp.Answers.Server = resolv.Servers[rand.Intn(len(resolv.Servers)-1)]
resp.Answers.Server = resolv.Servers[rand.Intn(len(resolv.Servers))]
}
}

View file

@ -1,47 +0,0 @@
package util
import (
"encoding/base64"
"fmt"
"io"
"net/http"
"github.com/miekg/dns"
)
func ResolveHTTPS(msg *dns.Msg, server string) (*dns.Msg, error) {
httpR := &http.Client{}
buf, err := msg.Pack()
if err != nil {
return nil, err
}
query := server + "?dns=" + base64.RawURLEncoding.EncodeToString(buf)
req, err := http.NewRequest("GET", query, nil)
if err != nil {
return nil, err
}
req.Header.Set("Accept", "application/dns-message")
res, err := httpR.Do(req)
if err != nil {
return nil, err
}
defer res.Body.Close()
if res.StatusCode != http.StatusOK {
return nil, fmt.Errorf("bad HTTP Request: %d", res.StatusCode)
}
fullRes, err := io.ReadAll(res.Body)
if err != nil {
return nil, err
}
response := dns.Msg{}
err = response.Unpack(fullRes)
if err != nil {
return nil, err
}
return &response, nil
}