Monday, 18 January 2021

How to extract the SOA DNS Server from a DNS Python Response

I'm trying to use DNS Python to lookup the SOA for a FQDN. From there, I am trying to isolate and extract the dns server name for the SOA, but I'm unable to find the correct object.

This is where I am at in my troubleshooting. I feel like i cam getting close with answer.response.additional, but it is still not the standalone server name.

Any advice on this? Thanks!

Code:

        import dns.resolver

        FQDN = 'testhostname.awesomedomain.com'

        answer = dns.resolver.query(FQDN, 'SOA', raise_on_no_answer=False)
        
        if answer.rrset is None:
            print(answer.response.authority[0].to_text())
            soa_data = answer.response.authority[0].to_text()
        else:
            print(answer)
            soa_data = answer
        
        rr = answer.response.authority[0]
        print(f"RR is {rr}")
        print(f"DataType is {rr.rdtype}")
        print(f"DNS SOA Type is {dns.rdatatype.SOA}")
        print(f"Target 1 is {rr.target}")
        print(f"Target 2 is {answer.canonical_name}")
        print(f"Target 3 is {answer.qname}")
        print(f"Target 4 is {answer.rdclass}")
        print(f"Target 5 is {answer.response}")
        print(f"Target 6 is {answer.response.additional}")
        print(f"Target 7 is {answer.response.additional.name}")



from How to extract the SOA DNS Server from a DNS Python Response

No comments:

Post a Comment