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

    原文作者:付炜超
    原文地址: https://www.jianshu.com/p/36d8c67d20e0
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞