Skip to content

Instantly share code, notes, and snippets.

@VGostyuzhov
Created September 25, 2017 09:21
Show Gist options
  • Save VGostyuzhov/53e272fd2d575a7f80a1b09f72878044 to your computer and use it in GitHub Desktop.
Save VGostyuzhov/53e272fd2d575a7f80a1b09f72878044 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import sys
import dns.resolver
resolver = dns.resolver.Resolver()
resolver.timeout = 5
resolver.lifetime = 5
if __name__ == '__main__':
source_file = sys.argv[1]
with open(source_file) as infile, open('result_MX.txt', 'wb') as outfile:
for domain in infile:
domain = domain.strip()
print('Getting MX records for: %s' % domain)
try:
answers = resolver.query(domain, 'mx')
outfile.write(domain + '\n')
except:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment