diff --git a/TODO.md b/TODO.md index c8cc644..477198f 100644 --- a/TODO.md +++ b/TODO.md @@ -67,3 +67,4 @@ - [ ] Mkdocs init project - [ ] Custom Index (Landing Page) - [ ] Homebrew - Goreleaser +- [ ] Separate Authority/Answer in JSON output. diff --git a/cmd/doggo/cli.go b/cmd/doggo/cli.go index f2c2603..29242e7 100644 --- a/cmd/doggo/cli.go +++ b/cmd/doggo/cli.go @@ -26,7 +26,6 @@ func main() { // Configure Flags. f := flag.NewFlagSet("config", flag.ContinueOnError) - hub.flag = f // Custom Help Text. f.Usage = renderCustomHelp diff --git a/cmd/doggo/hub.go b/cmd/doggo/hub.go index 9d25406..eb971d0 100644 --- a/cmd/doggo/hub.go +++ b/cmd/doggo/hub.go @@ -6,7 +6,6 @@ import ( "github.com/miekg/dns" "github.com/mr-karan/doggo/pkg/resolvers" "github.com/sirupsen/logrus" - "github.com/spf13/pflag" ) // Hub represents the structure for all app wide configuration. @@ -18,7 +17,6 @@ type Hub struct { Questions []dns.Question Resolver []resolvers.Resolver Nameservers []Nameserver - flag *pflag.FlagSet } // QueryFlags is used store the query params @@ -36,7 +34,6 @@ type QueryFlags struct { Ndots int `koanf:"ndots"` Color bool `koanf:"color"` Timeout time.Duration `koanf:"timeout"` - isNdotsSet bool } // Nameserver represents the type of Nameserver diff --git a/cmd/doggo/lookup.go b/cmd/doggo/lookup.go index 6c124e1..48430dc 100644 --- a/cmd/doggo/lookup.go +++ b/cmd/doggo/lookup.go @@ -14,6 +14,11 @@ import ( // to all resolvers. It returns a list of []resolver.Response from // each resolver func (hub *Hub) Lookup() ([][]resolvers.Response, error) { + // check if ndots is 0 (that means it's not supplied by user) + if hub.QueryFlags.Ndots == 0 { + // set the default as 1 + hub.QueryFlags.Ndots = 1 + } questions, err := hub.prepareQuestions() if err != nil { return nil, err @@ -79,7 +84,7 @@ func (hub *Hub) prepareQuestions() ([]dns.Question, error) { func fetchDomainList(d string, ndots int) ([]string, error) { if runtime.GOOS == "windows" { // TODO: Add a method for reading system default nameserver in windows. - return []string{d}, nil + return []string{dns.Fqdn(d)}, nil } cfg, err := dns.ClientConfigFromFile(DefaultResolvConfPath) if err != nil { diff --git a/cmd/doggo/output.go b/cmd/doggo/output.go index 75a390b..2d3a68f 100644 --- a/cmd/doggo/output.go +++ b/cmd/doggo/output.go @@ -20,6 +20,7 @@ type Output struct { Address string `json:"address"` TimeTaken string `json:"rtt"` Nameserver string `json:"nameserver"` + Status string `json:"status"` } type Query struct { @@ -68,6 +69,7 @@ func (hub *Hub) outputTerminal(out []Output) { yellow := color.New(color.FgYellow, color.Bold).SprintFunc() cyan := color.New(color.FgCyan, color.Bold).SprintFunc() red := color.New(color.FgRed, color.Bold).SprintFunc() + magenta := color.New(color.FgMagenta, color.Bold).SprintFunc() if !hub.QueryFlags.Color { color.NoColor = true // disables colorized output @@ -78,8 +80,16 @@ func (hub *Hub) outputTerminal(out []Output) { if hub.QueryFlags.DisplayTimeTaken { header = append(header, "Time Taken") } + outputStatus := false + for _, o := range out { + if dns.StringToRcode[o.Status] != dns.RcodeSuccess { + header = append(header, "Status") + outputStatus = true + } + } + table.SetHeader(header) - table.SetAutoWrapText(false) + table.SetAutoWrapText(true) table.SetAutoFormatHeaders(true) table.SetHeaderAlignment(tablewriter.ALIGN_LEFT) table.SetAlignment(tablewriter.ALIGN_LEFT) @@ -99,7 +109,7 @@ func (hub *Hub) outputTerminal(out []Output) { case "AAAA": typOut = blue(o.Type) case "MX": - typOut = red(o.Type) + typOut = magenta(o.Type) case "NS": typOut = cyan(o.Type) case "CNAME": @@ -116,6 +126,9 @@ func (hub *Hub) outputTerminal(out []Output) { if hub.QueryFlags.DisplayTimeTaken { output = append(output, o.TimeTaken) } + if outputStatus { + output = append(output, red(o.Status)) + } table.Append(output) } table.Render() @@ -166,6 +179,7 @@ func collectOutput(responses [][]resolvers.Response) []Output { Address: addr, TimeTaken: rtt, Nameserver: r.Nameserver, + Status: dns.RcodeToString[r.Message.Rcode], } out = append(out, o) } diff --git a/cmd/doggo/parse.go b/cmd/doggo/parse.go index d7cd417..27c3397 100644 --- a/cmd/doggo/parse.go +++ b/cmd/doggo/parse.go @@ -14,8 +14,6 @@ func (hub *Hub) loadQueryArgs() error { if err != nil { return err } - // check if ndots is set - hub.QueryFlags.isNdotsSet = isFlagPassed("ndots", hub.flag) // Load all fallbacks in internal query flags. hub.loadFallbacks()