make it functional

Signed-off-by: Sam Therapy <sam@samtherapy.net>
This commit is contained in:
Sam Therapy 2022-12-07 22:05:57 +01:00 committed by Gitea
parent 9bd06d0509
commit 4b0ead9f47
3 changed files with 37 additions and 10 deletions

View file

@ -57,14 +57,14 @@ func ParseCLI(args []string, version string) (*util.Options, error) {
if opts.Trace {
if opts.TLS || opts.HTTPS || opts.QUIC {
opts.Logger.Warn("Every query after the root query will only use UDP.")
opts.Logger.Warn("Every query after the root query will only use UDP/TCP")
}
if opts.Reverse {
opts.Logger.Error("Reverse queries are not currently supported")
}
opts.RD = false
opts.RD = true
}
opts.Logger.Info("Options fully populated")

View file

@ -27,6 +27,16 @@ func ParseDig(arg string, opts *util.Options) error {
switch arg {
case "trace", "notrace":
opts.Trace = isNo
if isNo == true {
opts.DNSSEC = true
opts.Display.Comments = false
opts.Display.Question = false
opts.Display.Opt = false
opts.Display.Answer = true
opts.Display.Authority = true
opts.Display.Additional = false
opts.Display.Statistics = false
}
// Set DNS query flags
case "aa", "aaflag", "aaonly":
opts.AA = isNo

33
main.go
View file

@ -91,23 +91,40 @@ func run(args []string) (opts *util.Options, code int, err error) {
fmt.Println(str)
if keepTracing {
// This part is the part that is broken
/*
this needs to be a random answer that comes from the DNS answers.
Since there is no recursion, and the answers are never recursive. The records should all be NS records.
var nothing []dns.RR
https://pkg.go.dev/github.com/miekg/dns@v1.1.50
*/
if opts.Request.Name == "." {
opts.Request.Server = resp.DNS.Answer[r.Intn(len(resp.DNS.Answer))].Header().Name
nothing = resp.DNS.Answer
} else {
opts.Request.Server = resp.DNS.Answer[r.Intn(len(resp.DNS.Ns))].Header().Name
nothing = resp.DNS.Ns
}
want := func(rr dns.RR) bool {
temp := strings.Split(rr.String(), "\t")
return temp[len(temp)-2] == "NS"
}
i := 0
for _, x := range nothing {
if want(x) {
nothing[i] = x
i++
}
}
nothing = nothing[:i]
nothing2 := nothing[r.Intn(len(nothing))]
v := strings.Split(nothing2.String(), "\t")
opts.Request.Server = strings.TrimSuffix(v[len(v)-1], ".")
opts.TLS = false
opts.HTTPS = false
opts.QUIC = false
opts.RD = false
opts.Request.Port = 53
}
}