2020-12-10 17:14:04 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-12-12 11:57:13 +01:00
|
|
|
"fmt"
|
2020-12-10 17:14:04 +01:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/miekg/dns"
|
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
)
|
|
|
|
|
2020-12-12 11:57:13 +01:00
|
|
|
// Lookup sends the DNS queries to the server.
|
2020-12-10 17:14:04 +01:00
|
|
|
func (hub *Hub) Lookup(c *cli.Context) error {
|
|
|
|
hub.prepareQuestions()
|
2020-12-12 11:57:13 +01:00
|
|
|
responses, err := hub.Resolver.Lookup(hub.Questions)
|
2020-12-10 17:14:04 +01:00
|
|
|
if err != nil {
|
|
|
|
hub.Logger.Error(err)
|
|
|
|
}
|
2020-12-12 11:57:13 +01:00
|
|
|
for _, r := range responses {
|
|
|
|
for _, a := range r.Message.Answer {
|
|
|
|
if t, ok := a.(*dns.A); ok {
|
|
|
|
fmt.Println(t.String())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-10 17:14:04 +01:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// prepareQuestions iterates on list of domain names
|
|
|
|
// and prepare a list of questions
|
|
|
|
// sent to the server with all possible combinations.
|
|
|
|
func (hub *Hub) prepareQuestions() {
|
|
|
|
var question dns.Question
|
|
|
|
for _, name := range hub.QueryFlags.QNames.Value() {
|
|
|
|
question.Name = dns.Fqdn(name)
|
|
|
|
// iterate on a list of query types.
|
|
|
|
for _, q := range hub.QueryFlags.QTypes.Value() {
|
|
|
|
question.Qtype = dns.StringToType[strings.ToUpper(q)]
|
|
|
|
// iterate on a list of query classes.
|
|
|
|
for _, c := range hub.QueryFlags.QClasses.Value() {
|
|
|
|
question.Qclass = dns.StringToClass[strings.ToUpper(c)]
|
|
|
|
// append a new question for each possible pair.
|
|
|
|
hub.Questions = append(hub.Questions, question)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|