Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MX Record lookup and check

I need to create a tool that will check a domains live mx records against what should be expected (we have had issues with some of our staff fiddling with them and causing all incoming mail to redirected into the void)

Now I won't lie, I'm not a competent programmer in the slightest! I'm about 40 pages into "dive into python" and can read and understand the most basic code. But I'm willing to learn rather than just being given an answer.

So would anyone be able to suggest which language I should be using?

I was thinking of using python and starting with something along the lines of using 0s.system() to do a (dig +nocmd domain.com mx +noall +answer) to pull up the records, I then get a bit confused about how to compare this to a existing set of records.

Sorry if that all sounds like nonsense!

Thanks Chris

like image 765
Christopher Long Avatar asked Dec 02 '10 15:12

Christopher Long


2 Answers

With dnspython module (not built-in, you must pip install it):

>>> import dns.resolver
>>> domain = 'hotmail.com'
>>> for x in dns.resolver.resolve(domain, 'MX'):
...     print(x.to_text())
...
5 mx3.hotmail.com.
5 mx4.hotmail.com.
5 mx1.hotmail.com.
5 mx2.hotmail.com.
like image 69
Paulo Scardine Avatar answered Oct 09 '22 06:10

Paulo Scardine


Take a look at dnspython, a module that should do the lookups for you just fine without needing to resort to system calls.

like image 30
Wooble Avatar answered Oct 09 '22 06:10

Wooble