forked from muety/wakapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemail_checker.go
55 lines (45 loc) · 929 Bytes
/
email_checker.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
package main
// Usage example:
// cat emails.txt go run email_checker.go > result.txt
import (
"bufio"
"fmt"
"log"
"net"
"os"
"regexp"
"strings"
)
const MailPattern = "[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\\.[a-zA-Z0-9-.]+"
var mailRegex *regexp.Regexp
func init() {
mailRegex = regexp.MustCompile(MailPattern)
}
func CheckEmailMX(email string) bool {
parts := strings.Split(email, "@")
if len(parts) != 2 {
return false
}
records, err := net.LookupMX(parts[1])
return len(records) > 0 && err == nil
}
func ValidateEmail(email string) bool {
return mailRegex.MatchString(email) && CheckEmailMX(email)
}
func main() {
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
email := scanner.Text()
if email == "" {
return
}
if ValidateEmail(email) {
fmt.Printf("[+] %s\n", email)
} else {
fmt.Printf("[-] %s\n", email)
}
}
if err := scanner.Err(); err != nil {
log.Fatal(err)
}
}