feat: custom response format
This commit is contained in:
parent
0aa3b36b35
commit
a7268f578f
7 changed files with 78 additions and 33 deletions
|
@ -1,18 +1,28 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// Lookup sends the DNS queries to the server.
|
||||
func (hub *Hub) Lookup(c *cli.Context) error {
|
||||
hub.prepareQuestions()
|
||||
err := hub.Resolver.Lookup(hub.Questions)
|
||||
responses, err := hub.Resolver.Lookup(hub.Questions)
|
||||
if err != nil {
|
||||
hub.Logger.Error(err)
|
||||
}
|
||||
for _, r := range responses {
|
||||
for _, a := range r.Message.Answer {
|
||||
if t, ok := a.(*dns.A); ok {
|
||||
fmt.Println(t.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
12
cmd/output.go
Normal file
12
cmd/output.go
Normal file
|
@ -0,0 +1,12 @@
|
|||
package main
|
||||
|
||||
// Output takes a list of `dns.Answers` and based
|
||||
// on the output format specified displays the information.
|
||||
// func (hub *Hub) Output(c *cli.Context) error {
|
||||
// hub.prepareQuestions()
|
||||
// answers, err := hub.Resolver.Lookup(hub.Questions)
|
||||
// if err != nil {
|
||||
// hub.Logger.Error(err)
|
||||
// }
|
||||
// return nil
|
||||
// }
|
|
@ -12,7 +12,7 @@ func (hub *Hub) loadQueryArgs(c *cli.Context) error {
|
|||
if err != nil {
|
||||
cli.Exit("Error parsing arguments", -1)
|
||||
}
|
||||
err = hub.loadResolver(c)
|
||||
err = hub.initResolver(c)
|
||||
if err != nil {
|
||||
cli.Exit("Error parsing nameservers", -1)
|
||||
}
|
||||
|
|
|
@ -7,9 +7,9 @@ import (
|
|||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// loadResolver checks for various flags and initialises
|
||||
// initResolver checks for various flags and initialises
|
||||
// the correct resolver based on the config.
|
||||
func (hub *Hub) loadResolver(c *cli.Context) error {
|
||||
func (hub *Hub) initResolver(c *cli.Context) error {
|
||||
// check if DOH flag is set.
|
||||
if hub.QueryFlags.IsDOH {
|
||||
rslvr, err := resolvers.NewDOHResolver(hub.QueryFlags.Nameservers.Value())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue