Created
March 22, 2022 14:37
-
-
Save rohzzn/ba8329e2de8fd717f7904be999e5187c to your computer and use it in GitHub Desktop.
Email Verifier Tool With Go
This file contains 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.Printf("domain,hasMX,hasSPF,sprRecord,hasDMARC,dmarcRecord\n") | |
for scanner.Scan() { | |
checkDomain(scanner.Text()) | |
} | |
if err := scanner.Err(); err != nil { | |
log.Fatal("Error: could not read from input: %v\n", err) | |
} | |
} | |
func checkDomain(domain string) { | |
var hasMX, hasSPF, hasDMARC bool | |
var spfRecord, dmarcRecord string | |
mxRecords, err := net.LookupMX(domain) | |
if err != nil { | |
log.Printf("Error: %v\n", err) | |
} | |
if len(mxRecords) > 0 { | |
hasMX = true | |
} | |
txtRecords, err := net.LookupTXT(domain) | |
if err != nil { | |
log.Printf("Error:%v\n", err) | |
} | |
for _, record := range txtRecords { | |
if strings.HasPrefix(record, "v=spf1") { | |
hasSPF = true | |
spfRecord = record | |
break | |
} | |
} | |
dmarcRecords, err := net.LookupTXT("_dmarc." + domain) | |
if err != nil { | |
log.Printf("ErrorL%v\n", err) | |
} | |
for _, record := range dmarcRecords { | |
if strings.HasPrefix(record, "v=DMARC1") { | |
hasDMARC = true | |
dmarcRecord = record | |
break | |
} | |
} | |
fmt.Printf("%v, %v, %v, %v, %v, %v", domain, hasMX, hasSPF, spfRecord, hasDMARC, dmarcRecord) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment