doggo/cmd/resolve.go

33 lines
720 B
Go
Raw Normal View History

2020-12-09 18:11:09 +01:00
package main
import (
"fmt"
"github.com/miekg/dns"
)
// Resolve resolves the domain name
func (hub *Hub) Resolve() {
2020-12-10 10:39:05 +01:00
var messages = make([]dns.Msg, 0, len(hub.Domains.Value()))
for _, d := range hub.Domains.Value() {
2020-12-09 18:11:09 +01:00
msg := dns.Msg{}
msg.Id = dns.Id()
msg.RecursionDesired = true
2020-12-10 10:39:05 +01:00
msg.Question = []dns.Question{(dns.Question{dns.Fqdn(d), dns.TypeA, dns.ClassINET})}
2020-12-09 18:11:09 +01:00
messages = append(messages, msg)
}
c := new(dns.Client)
for _, msg := range messages {
in, rtt, err := c.Exchange(&msg, "127.0.0.1:53")
if err != nil {
panic(err)
}
for _, ans := range in.Answer {
if t, ok := ans.(*dns.A); ok {
fmt.Println(t.String())
}
}
2020-12-10 10:39:05 +01:00
fmt.Println("rtt is", rtt, msg.Question[0].Name)
2020-12-09 18:11:09 +01:00
}
}