-
Notifications
You must be signed in to change notification settings - Fork 23
/
zonetransfer.go
50 lines (41 loc) · 912 Bytes
/
zonetransfer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package sonar
import (
"log"
"net"
"strings"
"github.com/miekg/dns"
)
func ZoneTransfer(domain string) Results {
results := NewResultSet()
fqdn := dns.Fqdn(domain)
servers, err := net.LookupNS(domain)
if err != nil {
log.Fatal(err)
}
for _, server := range servers {
msg := new(dns.Msg)
msg.SetAxfr(fqdn)
transfer := new(dns.Transfer)
answerChan, err := transfer.In(msg, net.JoinHostPort(server.Host, "53"))
if err != nil {
log.Println(err)
continue
}
for envelope := range answerChan {
if envelope.Error != nil {
log.Println(envelope.Error)
break
}
for _, rr := range envelope.RR {
switch v := rr.(type) {
case *dns.A:
results.Add(strings.TrimRight(v.Header().Name, "."), v.A.String())
case *dns.AAAA:
results.Add(strings.TrimRight(v.Header().Name, "."), v.AAAA.String())
default:
}
}
}
}
return results.Results()
}