Created
March 30, 2022 16:59
-
-
Save lesiki/7e151c639f6cbd9b13223781421cb60c to your computer and use it in GitHub Desktop.
Script to identify the mail host for a set of domains
This file contains hidden or 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 dns.resolver | |
input_domains = [ | |
"1.com", | |
"2.com", | |
"3.com", | |
"etc.com", | |
] | |
for domain in input_domains: | |
answer = None | |
try: | |
answers = dns.resolver.resolve(domain, 'MX') | |
answers = sorted(answers, key = lambda a: a.preference) | |
answer = answers[0] if len(answers) > 0 else None | |
except Exception as e: | |
answer = None | |
if answer is None: | |
print(f"{domain},,") | |
else: | |
best_guess = "" | |
exchange = str(answer.exchange) | |
if "google" in exchange: | |
best_guess = 'google' | |
elif "outlook.com" in exchange: | |
best_guess = "outlook" | |
elif "zoho" in exchange: | |
best_guess = "zoho" | |
print(f"{domain}, {exchange}, {best_guess}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Requires
dnspython
:python mx_lookup.py | tee output.csv