-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlookups.go
80 lines (70 loc) · 1.46 KB
/
lookups.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package validator
import (
"net"
"strings"
)
// A checks if host has at least one A record
func (v *V) A(host string) bool {
if host == "" {
return false
}
ips, err := net.LookupIP(host)
if err != nil {
v.cfg.Log("cannot get A records of %s: %v", host, err)
return false
}
return len(ips) > 0
}
// CNAME checks if host has at least one CNAME record
func (v *V) CNAME(host string) bool {
if host == "" {
return false
}
cname, err := net.LookupCNAME(host)
if err != nil {
v.cfg.Log("cannot get CNAME records of %s: %v", host, err)
return false
}
return cname != ""
}
// MX checks if host has at least one MX record
func (v *V) MX(host string) bool {
if host == "" {
return false
}
mxs, err := net.LookupMX(host)
if err != nil {
v.cfg.Log("cannot get MX records of %s: %v", host, err)
return false
}
return len(mxs) > 0
}
// NS checks if host has at least one NS record,
// and optionally checks if the NS record contains the given string
func (v *V) NS(host string, contains ...string) bool {
if host == "" {
return false
}
nss, err := net.LookupNS(host)
if err != nil {
v.cfg.Log("cannot get NS records of %s: %v", host, err)
return false
}
if len(nss) == 0 {
v.cfg.Log("%s doesn't have NS records", host)
return false
}
if len(contains) == 0 {
return true
}
if len(contains) > 0 {
for _, ns := range nss {
for _, c := range contains {
if strings.Contains(ns.Host, c) {
return true
}
}
}
}
return false
}