-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckDomain.go
67 lines (56 loc) · 1.49 KB
/
checkDomain.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
package main
import (
"log"
"net"
"strings"
)
type domainChecks struct {
HasMX bool `json:"hasMX"`
HasSPF bool `json:"hasSPF"`
SPFRecord string `json:"spfRecord"`
HasDMARC bool `json:"hasDMARC"`
DMARCRecord string `json:"dmarcRecord"`
}
func checkDomain(domain string) (domainChecks, error) {
hasMX := false
hasSPF := false
hasDMARC := false
var spfRecord, dmarcRecord string
// Function to check if a specific record is present in the TXT records
checkRecord := func(records []string, prefix string) (bool, string) {
for _, record := range records {
if strings.HasPrefix(record, prefix) {
return true, record
}
}
return false, ""
}
// Lookup MX records
mxRecords, err := net.LookupMX(domain)
if err != nil {
log.Printf("Error looking up MX records: %v\n", err)
}
// Check if MX records are present
hasMX = len(mxRecords) > 0
// Lookup TXT records
txtRecords, err := net.LookupTXT(domain)
if err != nil {
log.Printf("Error looking up TXT records: %v\n", err)
}
// Check for SPF record
hasSPF, spfRecord = checkRecord(txtRecords, "v=spf1")
// Lookup DMARC records
dmarcRecords, err := net.LookupTXT("_dmarc." + domain)
if err != nil {
log.Printf("Error looking up DMARC records: %v\n", err)
}
// Check for DMARC record
hasDMARC, dmarcRecord = checkRecord(dmarcRecords, "v=DMARC1")
return domainChecks{
HasMX: hasMX,
HasSPF: hasSPF,
SPFRecord: spfRecord,
HasDMARC: hasDMARC,
DMARCRecord: dmarcRecord,
}, err
}