Created
March 21, 2019 19:55
-
-
Save ttulttul/8c8461d70a45cb3e20a6d1ff6d146e0c 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
#!/usr/local/bin/python3 | |
from tld import get_fld | |
from google import google | |
import fileinput | |
import re | |
import dns.resolver | |
print("bank,domain,dmarc_p,dmarc_ruf,dmarc_rua") | |
for bank in fileinput.input(): | |
bank = bank.replace("BK", "BANK") | |
m = re.match("^([^/]+)", bank) | |
if m: | |
bank = m.group(1) | |
if "BANK" not in bank: | |
bank += " BANK" | |
bank += " home page" | |
r = google.search(bank, 1) | |
if r and type(r) is list: | |
domain = get_fld(r[0].link) | |
dmarc = "" | |
dmarc_fields = {} | |
try: | |
dmarc = dns.resolver.query("_dmarc.{}".format(domain), "TXT").response.answer[0][-1].strings[0] | |
dmarc = re.findall('(\w+=[^;]+)', str(dmarc)) | |
for field in dmarc: | |
k, v = field.split("=") | |
dmarc_fields[k] = v | |
except Exception as e: | |
pass | |
print(",".join(['"{}"'.format(x) for x in (bank, domain, dmarc_fields.get('p') or "", dmarc_fields.get('ruf') or "", dmarc_fields.get("rua") or "")]), flush=True) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment