Skip to content

Commit

Permalink
fix: pretty print NSID
Browse files Browse the repository at this point in the history
  • Loading branch information
natesales committed Jul 3, 2023
1 parent b4c4960 commit 50bbe5e
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions output.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"encoding/hex"
"encoding/json"
"fmt"
"io"
Expand Down Expand Up @@ -64,7 +65,38 @@ func printPrettyRR(a dns.RR, doWhois bool, out io.Writer) {
}
}

func prettyPrintNSID(opt []*dns.Msg, out io.Writer) {
for _, r := range opt {
for _, o := range r.Extra {
if o.Header().Rrtype == dns.TypeOPT {
opt := o.(*dns.OPT)
for _, e := range opt.Option {
if e.Option() == dns.EDNS0NSID {
nsidStr, err := hex.DecodeString(e.String())
if err != nil {
log.Warnf("error decoding NSID: %s", err)
return
}
mustWritef(out, "%s %s\n",
color("white", "NSID:"),
color("purple", string(nsidStr)),
)
return
}
}
}
}
}
}

func display(replies []*dns.Msg, server string, queryTime time.Duration, out io.Writer) error {
switch opts.Format {
case "pretty":
if opts.NSID {
prettyPrintNSID(replies, out)
}
}

for i, reply := range replies {
// Print answers
switch opts.Format {
Expand Down

0 comments on commit 50bbe5e

Please sign in to comment.