fix: output formatting
parent
d9715b1932
commit
90924eb27a
2
TODO.md
2
TODO.md
|
@ -14,7 +14,7 @@
|
||||||
## CLI Features
|
## CLI Features
|
||||||
- [ ] `digfile`
|
- [ ] `digfile`
|
||||||
- [x] `ndots` support
|
- [x] `ndots` support
|
||||||
- [x] `search path` support
|
- [x] `search list` support
|
||||||
- [x] JSON output
|
- [x] JSON output
|
||||||
- [x] Colorized output
|
- [x] Colorized output
|
||||||
- [x] Table output
|
- [x] Table output
|
||||||
|
|
|
@ -40,16 +40,15 @@ type JSONResponse struct {
|
||||||
func (hub *Hub) outputJSON(out []Output, msgs []resolvers.Response) {
|
func (hub *Hub) outputJSON(out []Output, msgs []resolvers.Response) {
|
||||||
// get the questions
|
// get the questions
|
||||||
queries := make([]Query, 0, len(msgs))
|
queries := make([]Query, 0, len(msgs))
|
||||||
for _, m := range msgs {
|
for _, ques := range hub.Questions {
|
||||||
for _, ques := range m.Message.Question {
|
q := Query{
|
||||||
q := Query{
|
Name: ques.Name,
|
||||||
Name: ques.Name,
|
Type: dns.ClassToString[ques.Qtype],
|
||||||
Type: dns.ClassToString[ques.Qtype],
|
Class: dns.ClassToString[ques.Qclass],
|
||||||
Class: dns.ClassToString[ques.Qclass],
|
|
||||||
}
|
|
||||||
queries = append(queries, q)
|
|
||||||
}
|
}
|
||||||
|
queries = append(queries, q)
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := JSONResponse{
|
resp := JSONResponse{
|
||||||
Response{
|
Response{
|
||||||
Output: out,
|
Output: out,
|
||||||
|
@ -73,6 +72,8 @@ func (hub *Hub) outputTerminal(out []Output) {
|
||||||
if hub.QueryFlags.DisplayTimeTaken {
|
if hub.QueryFlags.DisplayTimeTaken {
|
||||||
header = append(header, "Time Taken")
|
header = append(header, "Time Taken")
|
||||||
}
|
}
|
||||||
|
table.SetAutoWrapText(false)
|
||||||
|
table.SetAutoFormatHeaders(true)
|
||||||
table.SetHeader(header)
|
table.SetHeader(header)
|
||||||
|
|
||||||
for _, o := range out {
|
for _, o := range out {
|
||||||
|
@ -90,6 +91,10 @@ func (hub *Hub) outputTerminal(out []Output) {
|
||||||
// on the output format specified displays the information.
|
// on the output format specified displays the information.
|
||||||
func (hub *Hub) Output(responses []resolvers.Response) {
|
func (hub *Hub) Output(responses []resolvers.Response) {
|
||||||
out := collectOutput(responses)
|
out := collectOutput(responses)
|
||||||
|
if len(out) == 0 {
|
||||||
|
hub.Logger.Info("No records found")
|
||||||
|
hub.Logger.Exit(0)
|
||||||
|
}
|
||||||
if hub.QueryFlags.ShowJSON {
|
if hub.QueryFlags.ShowJSON {
|
||||||
hub.outputJSON(out, responses)
|
hub.outputJSON(out, responses)
|
||||||
} else {
|
} else {
|
||||||
|
@ -98,7 +103,7 @@ func (hub *Hub) Output(responses []resolvers.Response) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func collectOutput(responses []resolvers.Response) []Output {
|
func collectOutput(responses []resolvers.Response) []Output {
|
||||||
out := make([]Output, 0, len(responses))
|
var out []Output
|
||||||
// gather Output from the DNS Messages
|
// gather Output from the DNS Messages
|
||||||
for _, r := range responses {
|
for _, r := range responses {
|
||||||
var addr string
|
var addr string
|
||||||
|
@ -106,7 +111,16 @@ func collectOutput(responses []resolvers.Response) []Output {
|
||||||
switch t := a.(type) {
|
switch t := a.(type) {
|
||||||
case *dns.A:
|
case *dns.A:
|
||||||
addr = t.A.String()
|
addr = t.A.String()
|
||||||
|
case *dns.AAAA:
|
||||||
|
addr = t.AAAA.String()
|
||||||
|
case *dns.CNAME:
|
||||||
|
addr = t.Target
|
||||||
|
case *dns.MX:
|
||||||
|
addr = strconv.Itoa(int(t.Preference)) + " " + t.Mx
|
||||||
|
case *dns.SOA:
|
||||||
|
addr = t.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
h := a.Header()
|
h := a.Header()
|
||||||
name := h.Name
|
name := h.Name
|
||||||
qclass := dns.Class(h.Class).String()
|
qclass := dns.Class(h.Class).String()
|
||||||
|
|
|
@ -49,17 +49,6 @@ func NewSystemResolver(resolvFilePath string) (Resolver, error) {
|
||||||
// It's possible to send multiple question in one message
|
// It's possible to send multiple question in one message
|
||||||
// but some nameservers are not able to
|
// but some nameservers are not able to
|
||||||
func (s *SystemResolver) Lookup(questions []dns.Question) ([]Response, error) {
|
func (s *SystemResolver) Lookup(questions []dns.Question) ([]Response, error) {
|
||||||
for _, q := range questions {
|
|
||||||
domains := s.config.NameList(q.Name)
|
|
||||||
for _, d := range domains {
|
|
||||||
ques := dns.Question{
|
|
||||||
Name: d,
|
|
||||||
Qtype: q.Qtype,
|
|
||||||
Qclass: q.Qclass,
|
|
||||||
}
|
|
||||||
questions = append(questions, ques)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var (
|
var (
|
||||||
messages = prepareMessages(questions)
|
messages = prepareMessages(questions)
|
||||||
responses []Response
|
responses []Response
|
||||||
|
|
Loading…
Reference in New Issue