feat: Add status for non NOERROR responses
Closes https://github.com/mr-karan/doggo/issues/5pull/7/head
parent
90fee8799e
commit
8d1b6ad9fa
1
TODO.md
1
TODO.md
|
@ -67,3 +67,4 @@
|
||||||
- [ ] Mkdocs init project
|
- [ ] Mkdocs init project
|
||||||
- [ ] Custom Index (Landing Page)
|
- [ ] Custom Index (Landing Page)
|
||||||
- [ ] Homebrew - Goreleaser
|
- [ ] Homebrew - Goreleaser
|
||||||
|
- [ ] Separate Authority/Answer in JSON output.
|
||||||
|
|
|
@ -26,7 +26,6 @@ func main() {
|
||||||
|
|
||||||
// Configure Flags.
|
// Configure Flags.
|
||||||
f := flag.NewFlagSet("config", flag.ContinueOnError)
|
f := flag.NewFlagSet("config", flag.ContinueOnError)
|
||||||
hub.flag = f
|
|
||||||
|
|
||||||
// Custom Help Text.
|
// Custom Help Text.
|
||||||
f.Usage = renderCustomHelp
|
f.Usage = renderCustomHelp
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
"github.com/mr-karan/doggo/pkg/resolvers"
|
"github.com/mr-karan/doggo/pkg/resolvers"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/spf13/pflag"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Hub represents the structure for all app wide configuration.
|
// Hub represents the structure for all app wide configuration.
|
||||||
|
@ -18,7 +17,6 @@ type Hub struct {
|
||||||
Questions []dns.Question
|
Questions []dns.Question
|
||||||
Resolver []resolvers.Resolver
|
Resolver []resolvers.Resolver
|
||||||
Nameservers []Nameserver
|
Nameservers []Nameserver
|
||||||
flag *pflag.FlagSet
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// QueryFlags is used store the query params
|
// QueryFlags is used store the query params
|
||||||
|
@ -36,7 +34,6 @@ type QueryFlags struct {
|
||||||
Ndots int `koanf:"ndots"`
|
Ndots int `koanf:"ndots"`
|
||||||
Color bool `koanf:"color"`
|
Color bool `koanf:"color"`
|
||||||
Timeout time.Duration `koanf:"timeout"`
|
Timeout time.Duration `koanf:"timeout"`
|
||||||
isNdotsSet bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nameserver represents the type of Nameserver
|
// Nameserver represents the type of Nameserver
|
||||||
|
|
|
@ -14,6 +14,11 @@ import (
|
||||||
// to all resolvers. It returns a list of []resolver.Response from
|
// to all resolvers. It returns a list of []resolver.Response from
|
||||||
// each resolver
|
// each resolver
|
||||||
func (hub *Hub) Lookup() ([][]resolvers.Response, error) {
|
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()
|
questions, err := hub.prepareQuestions()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -79,7 +84,7 @@ func (hub *Hub) prepareQuestions() ([]dns.Question, error) {
|
||||||
func fetchDomainList(d string, ndots int) ([]string, error) {
|
func fetchDomainList(d string, ndots int) ([]string, error) {
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
// TODO: Add a method for reading system default nameserver in 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)
|
cfg, err := dns.ClientConfigFromFile(DefaultResolvConfPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -20,6 +20,7 @@ type Output struct {
|
||||||
Address string `json:"address"`
|
Address string `json:"address"`
|
||||||
TimeTaken string `json:"rtt"`
|
TimeTaken string `json:"rtt"`
|
||||||
Nameserver string `json:"nameserver"`
|
Nameserver string `json:"nameserver"`
|
||||||
|
Status string `json:"status"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Query struct {
|
type Query struct {
|
||||||
|
@ -68,6 +69,7 @@ func (hub *Hub) outputTerminal(out []Output) {
|
||||||
yellow := color.New(color.FgYellow, color.Bold).SprintFunc()
|
yellow := color.New(color.FgYellow, color.Bold).SprintFunc()
|
||||||
cyan := color.New(color.FgCyan, color.Bold).SprintFunc()
|
cyan := color.New(color.FgCyan, color.Bold).SprintFunc()
|
||||||
red := color.New(color.FgRed, color.Bold).SprintFunc()
|
red := color.New(color.FgRed, color.Bold).SprintFunc()
|
||||||
|
magenta := color.New(color.FgMagenta, color.Bold).SprintFunc()
|
||||||
|
|
||||||
if !hub.QueryFlags.Color {
|
if !hub.QueryFlags.Color {
|
||||||
color.NoColor = true // disables colorized output
|
color.NoColor = true // disables colorized output
|
||||||
|
@ -78,8 +80,16 @@ func (hub *Hub) outputTerminal(out []Output) {
|
||||||
if hub.QueryFlags.DisplayTimeTaken {
|
if hub.QueryFlags.DisplayTimeTaken {
|
||||||
header = append(header, "Time Taken")
|
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.SetHeader(header)
|
||||||
table.SetAutoWrapText(false)
|
table.SetAutoWrapText(true)
|
||||||
table.SetAutoFormatHeaders(true)
|
table.SetAutoFormatHeaders(true)
|
||||||
table.SetHeaderAlignment(tablewriter.ALIGN_LEFT)
|
table.SetHeaderAlignment(tablewriter.ALIGN_LEFT)
|
||||||
table.SetAlignment(tablewriter.ALIGN_LEFT)
|
table.SetAlignment(tablewriter.ALIGN_LEFT)
|
||||||
|
@ -99,7 +109,7 @@ func (hub *Hub) outputTerminal(out []Output) {
|
||||||
case "AAAA":
|
case "AAAA":
|
||||||
typOut = blue(o.Type)
|
typOut = blue(o.Type)
|
||||||
case "MX":
|
case "MX":
|
||||||
typOut = red(o.Type)
|
typOut = magenta(o.Type)
|
||||||
case "NS":
|
case "NS":
|
||||||
typOut = cyan(o.Type)
|
typOut = cyan(o.Type)
|
||||||
case "CNAME":
|
case "CNAME":
|
||||||
|
@ -116,6 +126,9 @@ func (hub *Hub) outputTerminal(out []Output) {
|
||||||
if hub.QueryFlags.DisplayTimeTaken {
|
if hub.QueryFlags.DisplayTimeTaken {
|
||||||
output = append(output, o.TimeTaken)
|
output = append(output, o.TimeTaken)
|
||||||
}
|
}
|
||||||
|
if outputStatus {
|
||||||
|
output = append(output, red(o.Status))
|
||||||
|
}
|
||||||
table.Append(output)
|
table.Append(output)
|
||||||
}
|
}
|
||||||
table.Render()
|
table.Render()
|
||||||
|
@ -166,6 +179,7 @@ func collectOutput(responses [][]resolvers.Response) []Output {
|
||||||
Address: addr,
|
Address: addr,
|
||||||
TimeTaken: rtt,
|
TimeTaken: rtt,
|
||||||
Nameserver: r.Nameserver,
|
Nameserver: r.Nameserver,
|
||||||
|
Status: dns.RcodeToString[r.Message.Rcode],
|
||||||
}
|
}
|
||||||
out = append(out, o)
|
out = append(out, o)
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,8 +14,6 @@ func (hub *Hub) loadQueryArgs() error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// check if ndots is set
|
|
||||||
hub.QueryFlags.isNdotsSet = isFlagPassed("ndots", hub.flag)
|
|
||||||
|
|
||||||
// Load all fallbacks in internal query flags.
|
// Load all fallbacks in internal query flags.
|
||||||
hub.loadFallbacks()
|
hub.loadFallbacks()
|
||||||
|
|
Loading…
Reference in New Issue