DNS/実装/python/dnslib/example/jp_queryについて、ここに記述してください。

   1 # -*- coding: utf-8 -*-
   2 
   3 """
   4     DNS Client - DiG-like CLI utility.
   5 
   6     Usage: python -m dnslib.client [options|--help]
   7 
   8 """
   9 from __future__ import print_function
  10 
  11 #import binascii,code,pprint,sys
  12 
  13 from dnslib.dns import DNSRecord,DNSHeader,DNSQuestion,DNSError,QTYPE,EDNS0
  14 from dnslib.digparser import DigParser
  15 
  16 if __name__ == '__main__':
  17 
  18     # import sys,time
  19     try:
  20         domain = 'qmail.jp'
  21         q = DNSRecord(q=DNSQuestion(domain, getattr(QTYPE,'NS')))
  22         address= '203.119.1.1'   # a.dns.jp
  23 
  24         a_pkt = q.send(address, 53, tcp=False)
  25         a = DNSRecord.parse(a_pkt)
  26         if a.header.tc :        # Truncated - retry in TCP mode
  27             a_pkt = q.send(address,port,tcp=True)
  28         a = DNSRecord.parse(a_pkt)
  29         
  30         # NXDOMAIN  rcode
  31         if a.header.rcode != 0 : # ['NOERROR', 'NXDOMAIN', 'SERVFAIL', 'REFUSED']:
  32            print (domain, a.header.rcode)
  33     #   print(";; Got answer:"); print(a.toZone())
  34         else:
  35           for r in a.auth:
  36             print (domain, '@'+str(r.rdata)[ :-1])
  37           print()
  38 
  39     except DNSError as e:
  40         p.error(e)
  41 
  42 #The default text representation of the DNSRecord is in zone file format:

MoinQ: DNS/実装/python/dnslib/example/jp_query (last edited 2021-02-28 04:29:12 by ToshinoriMaeno)