python module for nslookup

后端 未结 9 827
渐次进展
渐次进展 2020-12-10 00:27

Is there a python-module that\'s doing the same stuff as nslookup does? I am planning to use nslookup on digging some information regarding the domain of a URL to be scrappe

9条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-10 01:09

    $ sudo apt install python-dns
    $ python
    >>> import DNS
    >>> d = DNS.DnsRequest(server="1.1.1.1", timeout=1)                                       
    >>> r = d.req(name="stackoverflow.com", qtype="A")
    >>> [i['data'] for i in r.answers]
    ['151.101.129.69', '151.101.193.69', '151.101.1.69', '151.101.65.69']
    

    Further details like ttl can also be accessed, plus this approach has the advantage of letting you specify which nameserver to use, instead of just using your system's default.

提交回复
热议问题