Created
March 13, 2023 16:41
-
-
Save nickumia-reisys/7163dc0ad44d9ec14a3d84a1d7bf4974 to your computer and use it in GitHub Desktop.
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
import json | |
import xmltodict | |
with open('dmarc.xml', 'rb') as d: | |
dmarc = xmltodict.parse(d) | |
success = 0 | |
fail = 0 | |
for i in range(len(dmarc['feedback']['record'])): | |
source = dmarc['feedback']['record'][i]['row']['source_ip'] | |
dkim = dmarc['feedback']['record'][i]['row']['policy_evaluated']['dkim'] | |
spf = dmarc['feedback']['record'][i]['row']['policy_evaluated']['spf'] | |
spf_specific = dmarc['feedback']['record'][i]['auth_results']['spf']['result'] | |
domain = dmarc['feedback']['record'][i]['identifiers']['header_from'] | |
dkim_trail = [j['domain'] for j in dmarc['feedback']['record'][i]['auth_results']['dkim']] # if j['result'] == 'fail'] | |
spf_trail = dmarc['feedback']['record'][i]['auth_results']['spf']['domain'] | |
count = int(dmarc['feedback']['record'][i]['row']['count']) | |
if dkim != 'pass' or spf != 'pass': | |
fail += count | |
print(source, '\tdkim: ', dkim, '\tspf: ', spf_specific, domain, dkim_trail, spf_trail) | |
else: | |
success += count | |
print(source, '\tdkim: ', dkim, '\tspf: ', spf_specific, domain) | |
print("Success Rate %d/%d = %.2f" % (success, (success+fail), success/(success+fail))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Assuming dmarc report is saved to
dmarc.xml