Skip to content

Instantly share code, notes, and snippets.

@hinnerk
Created January 7, 2014 19:28
Show Gist options
  • Save hinnerk/8305312 to your computer and use it in GitHub Desktop.
Save hinnerk/8305312 to your computer and use it in GitHub Desktop.
Get mail exchange provider for a list of domains.
#!/usr/bin/env python2.6
import commands
domains = ['meine-domain.de', 'meine-andere-domain.com']
def slice_domain(o):
ergebnis = "UNDEFINED"
count = 0
for line in o.split("\n"):
if not line.startswith(";") and "mx" in line:
count += 1
ergebnis = line.split(" ")[-1]
if domain in ergebnis:
ergebnis = "EIGEN"
if count > 1:
ergebnis = "%s (multiple: %s)" % (ergebnis, count)
return ergebnis
for domain in domains:
s, o = commands.getstatusoutput("dig -t MX %s" % domain)
o = o.lower()
if s != 0:
ergebnis = "ERROR"
elif "google" in o:
ergebnis = "Google Apps"
elif "kundenserver" in o:
ergebnis = "1&1"
elif "ispgateway.de" in o:
ergebnis = "FOURTY SIX Media GmbH"
else:
ergebnis = slice_domain(o)
print "%s:\t%s" % (domain, ergebnis)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment