-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdmarc-check.py
75 lines (65 loc) · 2.45 KB
/
dmarc-check.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
import argparse
import dns.resolver
print("Author: iamsurve")
def check_dmarc(domain):
"""
Check if the DMARC record exists for the given domain.
"""
try:
dmarc_record = dns.resolver.resolve('_dmarc.' + domain, 'TXT')
for record in dmarc_record:
if 'v=DMARC1' in record.to_text():
return True
return False
except Exception as e:
print(f"[!] Error checking DMARC record for domain '{domain}': {e}")
return False
def check_spf(domain):
"""
Check if the SPF record exists for the given domain.
"""
try:
spf_record = dns.resolver.resolve(domain, 'TXT')
for record in spf_record:
if 'v=spf1' in record.to_text():
return True
return False
except Exception as e:
print(f"[!] Error checking SPF record for domain '{domain}': {e}")
return False
def check_dkim(domain, selector):
"""
Check if the DKIM record exists for the given domain and selector.
"""
try:
dkim_record = dns.resolver.resolve(f'{selector}._domainkey.{domain}', 'TXT')
for record in dkim_record:
if 'v=DKIM1' in record.to_text():
return True
return False
except Exception as e:
print(f"[!] Error checking DKIM record for domain '{domain}' and selector '{selector}': {e}")
return False
def main():
parser = argparse.ArgumentParser(description='Check DMARC, SPF, and DKIM records for multiple domains.')
parser.add_argument('domains', type=str, nargs='+', help='The domains to check')
parser.add_argument('--selector', type=str, default='default', help='The DKIM selector to check (default: default)')
args = parser.parse_args()
for domain in args.domains:
print(f"Checking DMARC record for domain '{domain}'...")
if check_dmarc(domain):
print("[+] DMARC record exists.")
else:
print("[-] DMARC record does not exist.")
print(f"Checking SPF record for domain '{domain}'...")
if check_spf(domain):
print("[+] SPF record exists.")
else:
print("[-] SPF record does not exist.")
print(f"Checking DKIM record for domain '{domain}' and selector '{args.selector}'...")
if check_dkim(domain, args.selector):
print("[+] DKIM record exists.")
else:
print("[-] DKIM record does not exist.")
if __name__ == "__main__":
main()