Determining the destination of an MX record and its preference

With the dns.resolver submodule, we can access the information stored in the ExChange mail exchange records to see which hosts have priority when exchanging emails via the internet.

You can find the following code in the dns_mx.py file:

import dns.resolver

answers = dns.resolver.query('dnspython.org', 'MX')
for rdata in answers:
print('Host', rdata.exchange, 'has preference', rdata.preference)

This is the output of the previous script:

Host alt1.aspmx.l.google.com. has preference 20
Host alt2.aspmx.l.google.com. has preference 20
Host aspmx2.googlemail.com. has preference 30
Host aspmx3.googlemail.com. has preference 30
Host aspmx.l.google.com. has preference 10
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset