Python:Dnspython工具包查询域名的DNS解析记录

Dnspython是一个基于Python的DNS工具包

相关资料

  • https://www.dnspython.org/
  • https://github.com/rthalley/dnspython
  • https://pypi.org/project/dnspython/
  • https://dnspython.readthedocs.io/

安装

pip install dnspython

代码示例

查询www.baidu.com 的A记录

import dns.resolver

if __name__ == '__main__':

    domain = 'www.baidu.com'

    query_object = dns.resolver.resolve(qname=domain, rdtype='A')
    for query_item in query_object.response.answer:
        for item in query_item.items:
            print("{} => {}".format(domain, item))

输出如下

www.baidu.com => www.a.shifen.com.
www.baidu.com => 220.181.38.150
www.baidu.com => 220.181.38.149

你可能感兴趣的:(Python,python,数据库,开发语言)