Skip to content

Commit

Permalink
feat: add txtconcat option
Browse files Browse the repository at this point in the history
  • Loading branch information
natesales committed Sep 11, 2023
1 parent dd5b989 commit 5dfb474
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,10 @@ Application Options:
--http3 Use HTTP/3 for DoH
--no-id-check Disable checking of DNS response ID
--no-reuse-conn Use a new connection for each query
--txtconcat Concatenate TXT responses
--recaxfr Perform recursive AXFR
-f, --format= Output format (pretty, json, yaml, raw)
(default: pretty)
--pretty-ttls Format TTLs in human readable format (default:
true)
-f, --format= Output format (pretty, json, yaml, raw) (default: pretty)
--pretty-ttls Format TTLs in human readable format (default: true)
--color Enable color output
--question Show question section
--answer Show answer section (default: true)
Expand All @@ -65,8 +64,7 @@ Application Options:
--aa Set AA (Authoritative Answer) flag in query
--ad Set AD (Authentic Data) flag in query
--cd Set CD (Checking Disabled) flag in query
--rd Set RD (Recursion Desired) flag in query
(default: true)
--rd Set RD (Recursion Desired) flag in query (default: true)
--ra Set RA (Recursion Available) flag in query
--z Set Z (Zero) flag in query
--t Set TC (Truncated) flag in query
Expand All @@ -81,8 +79,7 @@ Application Options:
--quic-alpn-tokens= QUIC ALPN tokens (default: doq, doq-i11)
--quic-no-pmtud Disable QUIC PMTU discovery
--quic-no-length-prefix Don't add RFC 9250 compliant length prefix
--default-rr-types= Default record types (default: A, AAAA, NS, MX,
TXT, CNAME)
--default-rr-types= Default record types (default: A, AAAA, NS, MX, TXT, CNAME)
--udp-buffer= Set EDNS0 UDP size in query (default: 1232)
-v, --verbose Show verbose log messages
--trace Show trace log messages
Expand Down
1 change: 1 addition & 0 deletions cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Flags struct {
HTTP3 bool `long:"http3" description:"Use HTTP/3 for DoH"`
NoIDCheck bool `long:"no-id-check" description:"Disable checking of DNS response ID"`
NoReuseConn bool `long:"no-reuse-conn" description:"Use a new connection for each query"`
TXTConcat bool `long:"txtconcat" description:"Concatenate TXT responses"`

RecAXFR bool `long:"recaxfr" description:"Perform recursive AXFR"`

Expand Down
26 changes: 26 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,25 @@ func parsePlusFlags(args []string) {
}
}

func txtConcat(m *dns.Msg) {
var answers []dns.RR
for _, answer := range m.Answer {
if answer.Header().Rrtype == dns.TypeTXT {
txt := answer.(*dns.TXT)

// Concat TXT responses if requested
if opts.TXTConcat {
log.Debugf("Concatenating TXT response: %+v", txt.Txt)
txt.Txt = []string{strings.Join(txt.Txt, "")}
}
answers = append(answers, txt)
} else {
answers = append(answers, answer)
}
}
m.Answer = answers
}

// parseServer parses opts.Server into a protocol and host:port
func parseServer() (string, string, error) {
var scheme, host, port, scopeId string
Expand Down Expand Up @@ -482,6 +501,13 @@ All long form (--) flags can be toggled with the dig-standard +[no]flag notation
}
queryTime := time.Since(startTime)

// Process TXT parsing
if opts.TXTConcat {
for _, reply := range replies {
txtConcat(reply)
}
}

if opts.NSID && opts.Format == "pretty" {
output.PrettyPrintNSID(replies, out)
}
Expand Down

0 comments on commit 5dfb474

Please sign in to comment.