-
Notifications
You must be signed in to change notification settings - Fork 0
/
oldversion.py
104 lines (85 loc) · 2.76 KB
/
oldversion.py
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import re
import dns.resolver
import socket
# from check_existing_email import verify_email
# from validate_email_address import validate_email
# Color codes
#https://woodpecker.co/signup/
BLACK = '\033[30m'
RED = '\033[31m'
GREEN = '\033[32m'
YELLOW = '\033[33m'
BLUE = '\033[34m'
MAGENTA = '\033[35m'
CYAN = '\033[36m'
WHITE = '\033[37m'
RESET = '\033[0m'
# Define the 'POPG' ASCII art
popg_art = CYAN + f"""
PPPP OOO PPPP GGGGG
PP PP OO OO PP PP GG GG
PP PP OO OO PP PP GG
PP PP OO OO PP PP GG GGGG
PPPPPPP OO OO PPPPPPP GG GG
PP OO OO PP GG GG
PP OO OO PP GG GG
PP OOO PP GGGG
{GREEN}---------------------
|{RED}PmailValidator v1.0 {GREEN}|
{GREEN}---------------------
""" + RESET
# Print the 'POPG' ASCII art with color
print(popg_art)
print()
print()
def validate_email(email):
# Check if the email address is properly formatted
if not re.match(r"[^@]+@[^@]+\.[^@]+", email):
return False
# Extract the domain from the email address
domain = email.split("@")[1]
try:
# Check if the domain has valid MX records
dns.resolver.resolve(domain, 'MX')
except (dns.resolver.NoAnswer, dns.resolver.NXDOMAIN, dns.resolver.Timeout):
return False
# Check if the domain has a reachable mail exchanger
try:
reachable = socket.getaddrinfo(domain, 25)
# print(reachable)
except socket.gaierror:
return False
return True
# Prompt the user for the file path
file_path = input(f"{BLUE}[+] Enter the file path: ")
try:
with open(file_path, "r") as file:
email_addresses = file.readlines()
except FileNotFoundError:
print(f"{RED}[+] File not found!")
exit()
except PermissionError:
print(f"{RED}Permission denied to access the file!")
exit()
except Exception as e:
print(f"{RED}An error occurred while opening the file:", str(e))
exit()
# Remove leading/trailing spaces from email addresses
email_addresses = [email.strip() for email in email_addresses]
valid_email_addresses = []
for email_address in email_addresses:
if validate_email(email_address):
valid_email_addresses.append(email_address)
output_file_path = "valid_emails.txt"
try:
with open(output_file_path, "w") as output_file:
for email_address in valid_email_addresses:
output_file.write(f"{email_address}\n")
except PermissionError:
print("Permission denied to write to the file!")
exit()
except Exception as e:
print("An error occurred while writing to the file:", str(e))
exit()
print()
print(f"{GREEN}[+] Validation completed. Valid email addresses have been written to valid_emails.txt.")