Skip to content

Commit

Permalink
feat: add nsid-only parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
natesales committed Jul 16, 2024
1 parent cf7c2e5 commit de71183
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
1 change: 1 addition & 0 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Flags struct {
Reverse bool `short:"x" long:"reverse" description:"Reverse lookup"`
DNSSEC bool `short:"d" long:"dnssec" description:"Set the DO (DNSSEC OK) bit in the OPT record"`
NSID bool `short:"n" long:"nsid" description:"Set EDNS0 NSID opt"`
NSIDOnly bool `short:"N" long:"nsid-only" description:"Set EDNS0 NSID opt and query only for the NSID"`
ClientSubnet string `long:"subnet" description:"Set EDNS0 client subnet"`
Chaos bool `short:"c" long:"chaos" description:"Use CHAOS query class"`
Class uint16 `short:"C" description:"Set query class (default: IN 0x01)" default:"1"`
Expand Down
13 changes: 11 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,10 @@ All long form (--) flags can be toggled with the dig-standard +[no]flag notation
opts.Class = dns.ClassCHAOS
}

if opts.NSIDOnly {
opts.NSID = true
}

// Create TLS config
tlsConfig := &tls.Config{
InsecureSkipVerify: opts.TLSInsecureSkipVerify,
Expand Down Expand Up @@ -499,8 +503,13 @@ All long form (--) flags can be toggled with the dig-standard +[no]flag notation
Opts: &opts,
}

if opts.NSID && (opts.Format == output.FormatPretty || opts.Format == output.FormatColumn) {
printer.PrettyPrintNSID(entries)
if (opts.NSID && (opts.Format == output.FormatPretty || opts.Format == output.FormatColumn)) || opts.NSIDOnly {
printer.PrettyPrintNSID(entries, !opts.NSIDOnly)
}

// Skip printing if NSIDOnly is set
if opts.NSIDOnly {
errChan <- nil
}

switch opts.Format {
Expand Down
12 changes: 9 additions & 3 deletions output/pretty.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
)

// PrettyPrintNSID prints the NSID from a slice of entries
func (p Printer) PrettyPrintNSID(entries []*Entry) {
func (p Printer) PrettyPrintNSID(entries []*Entry, printPrefix bool) {
for _, entry := range entries {
for _, r := range entry.Replies {
for _, o := range r.Extra {
Expand All @@ -33,8 +33,14 @@ func (p Printer) PrettyPrintNSID(entries []*Entry) {
if len(entries) > 1 {
suffix = fmt.Sprintf(" (%s)", entry.Server)
}
util.MustWritef(p.Out, "%s %s%s\n",
util.Color(util.ColorWhite, "NSID:"),

var prefix string
if printPrefix {
prefix = util.Color(util.ColorWhite, "NSID:") + " "
}

util.MustWritef(p.Out, "%s%s%s\n",
prefix,
util.Color(util.ColorPurple, string(nsidStr)),
suffix,
)
Expand Down

0 comments on commit de71183

Please sign in to comment.