-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathspf_info.go
42 lines (37 loc) · 1.16 KB
/
spf_info.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
package main
import (
"fmt"
"strings"
)
// getSPF fetches and analyzes the SPF record for a given domain.
func getSPF(domain string) (bool, string, string) {
txtRecords, err := getTXT(domain)
if err != nil {
return false, "Error fetching TXT records", ""
}
for _, record := range txtRecords {
suffix := ""
if strings.Contains(record, "-all") {
suffix = "-all"
} else if strings.Contains(record, "~all") {
suffix = "~all"
}
if strings.HasPrefix(record, "v=spf1") {
return true, record, suffix
} else if strings.Contains(record, "spf") || strings.Contains(record, "-all") || strings.Contains(record, "~all") {
return false, record, suffix
}
}
return false, " No SPF record", ""
}
// GetSPFPrompt is prompt for spf
func getSPFPrompt(input string) {
spfValid, spfRecord, _ := getSPF(input)
if spfValid || spfRecord != "No SPF record" {
coloredSPFRecord := colorCodeSPFRecord(spfRecord, spfValid)
fmt.Printf("\033[38;5;39m SPF Record: %s\033[0m\n", coloredSPFRecord)
} else {
coloredSPFRecord := colorCodeSPFRecord(spfRecord, false) // "No SPF record" will be red
fmt.Printf("\033[38;5;39m SPF Record: %s\033[0m\n", coloredSPFRecord)
}
}