トップ 一覧 検索 ヘルプ RSS ログイン

PRG-py_dnspythonの変更点

  • 追加された行はこのように表示されます。
  • 削除された行はこのように表示されます。
! dnspython

 $ pip install dnspython

 $ pip install dnspython3

zone fileが/path/to/example.zone とすると

ゾーンファイルを表示するプログラム

 import dns
 from dns import (zone, rdataclass, rdatatype)
 
 zone_example = zone.from_file("/path/to/example.zone")
 
 print("Origin: {}".format(zone_example.origin))
 
 for name, node in zone_example.nodes.items():
    for rdataset in node.rdatasets:
        for rdata in rdataset:
            print("{}: {} {} {}".format(name,
                                        rdataclass.to_text(rdataset.rdclass),
                                        rdatatype.to_text(rdataset.rdtype),
                                        rdataset.ttl))
 
            rdata_property_names = set(dir(rdata)) - set(dir(dns.rdata.Rdata))
 
            for property_name in rdata_property_names:
                if not property_name.startswith("_"):
                    print("    {}: {}".format(property_name,
                                              getattr(rdata, property_name)))


表示サンプル
 node_gateway = zone_example.find_node("gateway")
 rdataset_gateway_a = zone_example.find_rdataset("gateway", "A")
 rrset_gateway_a = zone_example.find_rrset("gateway", "A")
 
 print(node_gateway)
 print(node_gateway.rdatasets)
 print(rdataset_gateway_a.__repr__(),
      rdataset_gateway_a,
      hasattr(rdataset_gateway_a, "name"))
 print(rrset_gateway_a.__repr__(),
      rrset_gateway_a,
      hasattr(rrset_gateway_a, "name"))