wownero/external/unbound/libunbound/python/examples/dnssec_test.py

37 lines
1.3 KiB
Python
Raw Normal View History

2014-10-05 21:44:31 +00:00
#!/usr/bin/env python
2015-05-31 14:36:48 +00:00
from __future__ import print_function
2014-10-05 21:44:31 +00:00
from unbound import ub_ctx, RR_TYPE_A, RR_TYPE_RRSIG, RR_TYPE_NSEC, RR_TYPE_NSEC3
import ldns
def dnssecParse(domain, rrType=RR_TYPE_A):
print("Resolving domain", domain)
s, r = resolver.resolve(domain)
print("status: %s, secure: %s, rcode: %s, havedata: %s, answer_len; %s" % (s, r.secure, r.rcode_str, r.havedata, r.answer_len))
s, pkt = ldns.ldns_wire2pkt(r.packet)
if s != 0:
raise RuntimeError("Error parsing DNS packet")
rrsigs = pkt.rr_list_by_type(RR_TYPE_RRSIG, ldns.LDNS_SECTION_ANSWER)
2015-05-31 14:36:48 +00:00
print("RRSIGs from answer:", sorted(rrsigs))
2014-10-05 21:44:31 +00:00
rrsigs = pkt.rr_list_by_type(RR_TYPE_RRSIG, ldns.LDNS_SECTION_AUTHORITY)
2015-05-31 14:36:48 +00:00
print("RRSIGs from authority:", sorted(rrsigs))
2014-10-05 21:44:31 +00:00
nsecs = pkt.rr_list_by_type(RR_TYPE_NSEC, ldns.LDNS_SECTION_AUTHORITY)
2015-05-31 14:36:48 +00:00
print("NSECs:", sorted(nsecs))
2014-10-05 21:44:31 +00:00
nsec3s = pkt.rr_list_by_type(RR_TYPE_NSEC3, ldns.LDNS_SECTION_AUTHORITY)
2015-05-31 14:36:48 +00:00
print("NSEC3s:", sorted(nsec3s))
2014-10-05 21:44:31 +00:00
print("---")
resolver = ub_ctx()
resolver.add_ta(". IN DS 19036 8 2 49AAC11D7B6F6446702E54A1607371607A1A41855200FD2CE1CDDE32F24E8FB5")
dnssecParse("nic.cz")
dnssecParse("nonexistent-domain-blablabla.cz")
dnssecParse("nonexistent-domain-blablabla.root.cz")