How do we get TXT, CNAME and SOA records from dnspython?

前端 未结 3 534
暗喜
暗喜 2021-02-04 07:34

I have a requirement to have a dns query function to query a server for various records. I figured out how to get the MX record (most of the examples show this), A record and NS

3条回答
  •  感情败类
    2021-02-04 07:48

    You can try something a bit different.

    Instead of querying each time per record type, you can make a single query for ANY record. This way if that domain has both TXT, CNAME etc... you'll get one object with all the data.

    from dns.resolver import dns
    name_server = '8.8.8.8' #Google's DNS server
    ADDITIONAL_RDCLASS = 65535
    request = dns.message.make_query('google.com', dns.rdatatype.ANY)
    request.flags |= dns.flags.AD
    request.find_rrset(request.additional, dns.name.root, ADDITIONAL_RDCLASS,
                           dns.rdatatype.OPT, create=True, force_unique=True)       
    response = dns.query.udp(request, name_server)
    

    Hope this might assist you.

提交回复
热议问题