Skip to content

Commit

Permalink
feat: add support for common query types
Browse files Browse the repository at this point in the history
Using `--any` it will query multiple common record types.
  • Loading branch information
mr-karan committed Jul 2, 2024
1 parent f07b749 commit adfd23a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 2 additions & 0 deletions cmd/doggo/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
5 changes: 4 additions & 1 deletion internal/app/questions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 13 additions & 1 deletion pkg/models/models.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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)
}

0 comments on commit adfd23a

Please sign in to comment.