dnspython
dnspython 一个Python实现的一个DNS工具包,利用其查询功能来实现dns的服务监控及解析结果的校验。 安装 pip install dnspython 解析域名为IP from dns import resolver f = open('ddd.log', 'w') with open('urls.txt', 'r') as fp: for line in fp: try: url = line[7:].strip() ans = resolver.query(url, 'A') # A记录,将主机名转换为IP地址; # for x in ans.response.answer: # 获取结果 # for y in x.items: # print(y) t = url + '||Successful!' except Exception as e: t = url + '||' + str(e) print('resolver error!') finally: f.write(t + '\n') f.close() urls.txt http://www.lyskjqbyjs.cn http://www.haict.edu.cn http://news.kf.cn http://www.henanjubao.com http://huixiangtan.smx