[root@bogon dns]# vim MX.py
!/usr/bin/env python
import dns.resolver
domain = raw_input(‘Please input an domain: ‘)
MX = dns.resolver.query(domain, ‘MX’)
for i in MX:
print ‘MX preference =’, i.preference, ‘mail exchanger =’, i.exchange
测试:
[root@bogon dns]# python MX.py
Please input an domain: baidu.com
MX preference = 20 mail exchanger = mx50.baidu.com.
MX preference = 20 mail exchanger = jpmx.baidu.com.
MX preference = 10 mail exchanger = mx.n.shifen.com.
MX preference = 20 mail exchanger = mx1.baidu.com.
[root@bogon dns]#