gui-host-lookup/generic/spf_dmarc.py

20 lines
596 B
Python
Raw Normal View History

from checkdmarc.dmarc import check_dmarc
from checkdmarc.spf import check_spf
import validators
def extract_domain(host: str) -> str:
if validators.email(host):
host = host.split('@')[1]
return host
def lookup(host: str) -> tuple:
host = extract_domain(host)
result_dmarc = check_dmarc(host)
dmarc_quarantine = result_dmarc['record'].split(';')[1]
result_spf = check_spf(host)
# spf_includes = result_spf['record'].split()[1:]
spf_includes = ', '.join(str(item) for item in result_spf['record'].split()[1:])
return (dmarc_quarantine, spf_includes)