最近,实验室布置一个简单的任务,对学校官网www.hitwh.edu.cn进行DNS查询
要求使用python,既然布置了,那就做做呗。
1.pyDNS库
在linux上用python3装pyDNS总是会出现问题,所以放弃了python3,最后总算是用python2装好了pyDNS库
>>>improt DNS
>>>
import成功了,这是第一步
下面开始写代码
!/usr/bin/env python
Basiv DNS library example - Chapter 4 DNS-basic.py
import sys
import DNS
import time
query = sys.argv[0]
DNS.DiscoverNameServers()
reqobj = DNS.Request("www.hitwh.edu.cn")
answerobj = reqobj.req(name = query, qtype = DNS.Type.A)
if not len(answerobj.answers):
print ("Not found.")
for item in answerobj.answers:
print ("%-5s %s" % (item['typename'], item['data']))
reqobj0 = DNS.Request("hitwh.edu.cn")
answerobj = reqobj0.req(name = query, qtype = DNS.Type.ANY)
if not len(answerobj.answers):
print ("Not found.")
for item in answerobj.answers:
print ("%-5s %s" % (item['typename'], item['data']))
print ("WHEN:", time.asctime(time.localtime(time.time())))
得到的结果如图所示: