From adfd23a7371f66bbdad9eec5d515b2ab0c199ced Mon Sep 17 00:00:00 2001 From: Karan Sharma Date: Tue, 2 Jul 2024 12:50:15 +0530 Subject: [PATCH] feat: add support for common query types Using `--any` it will query multiple common record types. --- cmd/doggo/cli.go | 2 ++ internal/app/questions.go | 5 ++++- pkg/models/models.go | 14 +++++++++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/cmd/doggo/cli.go b/cmd/doggo/cli.go index 6517d56..4933243 100644 --- a/cmd/doggo/cli.go +++ b/cmd/doggo/cli.go @@ -120,6 +120,8 @@ func setupFlags() *flag.FlagSet { f.String("tls-hostname", "", "Hostname for certificate verification") f.Bool("skip-hostname-verification", false, "Skip TLS Hostname Verification") + f.Bool("any", false, "Query all supported DNS record types") + f.BoolP("json", "J", false, "Set the output format as JSON") f.Bool("short", false, "Short output format") f.Bool("time", false, "Display how long the response took") diff --git a/internal/app/questions.go b/internal/app/questions.go index b0b7a1b..256d8ad 100644 --- a/internal/app/questions.go +++ b/internal/app/questions.go @@ -5,13 +5,16 @@ import ( "strings" "github.com/miekg/dns" + "github.com/mr-karan/doggo/pkg/models" ) // LoadFallbacks sets fallbacks for options // that are not specified by the user but necessary // for the resolver. func (app *App) LoadFallbacks() { - if len(app.QueryFlags.QTypes) == 0 { + if app.QueryFlags.QueryAny { + app.QueryFlags.QTypes = models.GetCommonRecordTypes() + } else if len(app.QueryFlags.QTypes) == 0 { app.QueryFlags.QTypes = append(app.QueryFlags.QTypes, "A") } if len(app.QueryFlags.QClasses) == 0 { diff --git a/pkg/models/models.go b/pkg/models/models.go index 07c8611..0c8913d 100644 --- a/pkg/models/models.go +++ b/pkg/models/models.go @@ -1,6 +1,9 @@ package models -import "time" +import ( + "strings" + "time" +) const ( // DefaultTLSPort specifies the default port for a DNS server connecting over TCP over TLS. @@ -39,6 +42,7 @@ type QueryFlags struct { Strategy string `koanf:"strategy" strategy:"-"` InsecureSkipVerify bool `koanf:"skip-hostname-verification" skip-hostname-verification:"-"` TLSHostname string `koanf:"tls-hostname" tls-hostname:"-"` + QueryAny bool `koanf:"any" json:"any"` } // Nameserver represents the type of Nameserver @@ -47,3 +51,11 @@ type Nameserver struct { Address string Type string } + +// CommonRecordTypes is a string containing all common DNS record types +const CommonRecordTypes = "A AAAA CNAME MX NS PTR SOA SRV TXT CAA" + +// GetCommonRecordTypes returns a slice of common DNS record types +func GetCommonRecordTypes() []string { + return strings.Fields(CommonRecordTypes) +}