python自动化运维

dnspython实现MX记录查询

2016-01-14  本文已影响449人  如来自然

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

上一篇下一篇

猜你喜欢

热点阅读