Created
March 25, 2022 14:09
-
-
Save xandersavvy/1d0139a206dbdb7b6877daf321445915 to your computer and use it in GitHub Desktop.
Go Lang MX record checker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "bufio" | |
| "fmt" | |
| "log" | |
| "net" | |
| "os" | |
| "strings" | |
| ) | |
| func main() { | |
| scanner := bufio.NewScanner(os.Stdin) | |
| fmt.Println("Enter email address or type 0 to exit: ") | |
| for scanner.Scan() { | |
| checkDomain(scanner.Text()) //function to perform check domain | |
| fmt.Println("Enter email address or type 0 to exit: ") | |
| } | |
| if err := scanner.Err(); err != nil { | |
| log.Fatal(err) | |
| } | |
| } | |
| func checkDomain(domain string) { | |
| //exit if 0 is entered | |
| if domain == "0" || domain == "" { | |
| os.Exit(0) | |
| } | |
| var hasMX, hasSPF, hasDMARC bool | |
| var spfRecord, dmarcRecord string | |
| //check if domain has MX record | |
| mxRecords, err := net.LookupMX(domain) | |
| if err != nil { | |
| log.Println("No MX records found", err) | |
| } | |
| if len(mxRecords) > 0 { | |
| hasMX = true | |
| } | |
| //check if domain has SPF record | |
| txtRecords, err := net.LookupTXT(domain) | |
| if err != nil { | |
| log.Println("No TXT records found", err) | |
| } | |
| for _, record := range txtRecords { | |
| if strings.HasPrefix(record, "v=spf1") { | |
| hasSPF = true | |
| spfRecord = record | |
| break | |
| } | |
| } | |
| //check if domain has DMARC record | |
| dmarcRecords, err := net.LookupTXT("_dmarc." + domain) | |
| if err != nil { | |
| log.Println("No DMARC records found", err) | |
| } | |
| for _, record := range dmarcRecords { | |
| if strings.HasPrefix(record, "v=DMARC1") { | |
| hasDMARC = true | |
| dmarcRecord = record | |
| break | |
| } | |
| } | |
| //print results | |
| fmt.Println("Domain: ", domain) | |
| fmt.Println("Has MX records: ", hasMX) | |
| fmt.Println("Has SPF records: ", hasSPF) | |
| fmt.Println("SPF record: ", spfRecord) | |
| fmt.Println("Has DMARC records: ", hasDMARC) | |
| fmt.Println("DMARC record: ", dmarcRecord) | |
| fmt.Println("") | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment