dnspython实现MX记录查询

[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]#

你可能感兴趣的:(dnspython实现MX记录查询)