-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_spf_dmarc.py
28 lines (24 loc) · 1.05 KB
/
check_spf_dmarc.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
import dns.resolver
import checkdmarc
# will be passed from the backend when calling classfication API, this is an example
senderAddress = "[email protected]"
domain = checkdmarc.get_base_domain(senderAddress) # get the base email server domain from the sender address
# source: https://www.thierolf.org/blog/2021/small-python-script-to-quick-test-dmarc-dkim-and-spf-records/
try:
test_dmarc = dns.resolver.resolve('_dmarc.' + domain , 'TXT')
for dns_data in test_dmarc:
if 'DMARC1' in str(dns_data):
print(" [PASS] DMARC record found!")
# print out the DMARC record if you want to see it
# print(dns_data)
except:
print(" [FAIL] DMARC record not found.")
try:
test_spf = dns.resolver.resolve(domain , 'TXT')
for dns_data in test_spf:
if 'spf1' in str(dns_data):
print (" [PASS] SPF record found!")
# print out the SPF record if you want to see it
# print(dns_data)
except:
print (" [FAIL] SPF record not found.")