Python-模块-dnspython

安装:
    # www.dnspython.org/kits/1.12.0/dnspython-1.12.0.tar.gz
    # tar -zxvf dnspython-1.12.0.tar.gz  
    # cd dnspython-1.12.0  
    # python setup.py install

qyery 引擎定义:
    query(self,qname,rdtype=1,rdclass=1,tcp=False,source=None,raise_on_no_answer=True,source_port=0)
A记录:
import dns.resolver
domain = raw_input('Please input an domain:')
A=dns.resolver.query(domain,'A')
for i in A.response.answer:
    for j in i.items:
        print j    

Please input an domain:www.sina.com.cn
jupiter.sina.com.cn.
auriga.sina.com.cn.
61.172.201.237
61.172.201.195
61.172.201.194
61.172.201.239

MX记录:
[root@node5 DNS]# cat mx.py
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@node5 DNS]# python mx.py
Please input an domain:163.com
MX preference= 50 Mail exchanger= 163mx00.mxmail.netease.com.
MX preference= 10 Mail exchanger= 163mx01.mxmail.netease.com.
MX preference= 10 Mail exchanger= 163mx02.mxmail.netease.com.
MX preference= 10 Mail exchanger= 163mx03.mxmail.netease.com.


NS记录:
[root@node5 DNS]# cat ns.py
import dns.resolver
domain=raw_input('Please input an domain:')
ns=dns.resolver.query(domain,'NS')
for i in ns.response.answer:
    for j in i.items:
        print j.to_text()

[root@node5 DNS]# python ns.py
Please input an domain:baidu.com
ns7.baidu.com.
dns.baidu.com.
ns3.baidu.com.
ns2.baidu.com.
ns4.baidu.com.

CNAME记录:
[root@node5 DNS]# cat cname.py
import dns.resolver
domain = raw_input('Please input an domain:')
cname = dns.resolver.query(domain,'CNAME')
for i in cname.response.answer:
    for j in i.items:
        print j.to_text()




分割线
感谢打赏
江西数库信息技术有限公司
YWSOS.COM 平台代运维解决方案
 评论
 发表评论
姓   名:

Powered by AKCMS