Пример #1
0
    p.add_argument("--dnssec",action='store_true',default=False,
                    help="Set DNSSEC (DO/AD) flags in query (default: false)")
    p.add_argument("--debug",action='store_true',default=False,
                    help="Drop into CLI after request (default: false)")
    p.add_argument("domain",metavar="<domain>",
                    help="Query domain")
    p.add_argument("qtype",metavar="<type>",default="A",nargs="?",
                    help="Query type (default: A)")
    args = p.parse_args()

    # Construct request
    try:
        q = DNSRecord(q=DNSQuestion(args.domain,getattr(QTYPE,args.qtype)))

        if args.dnssec:
            q.add_ar(EDNS0(flags="do",udp_len=4096))
            q.header.ad = 1

        address,_,port = args.server.partition(':')
        port = int(port or 53)

        if args.query:
            print(";; Sending%s:" % (" (TCP)" if args.tcp else ""))
            if args.hex:
                print(";; QUERY:",binascii.hexlify(q.pack()).decode())
            print(q)
            print()

        a_pkt = q.send(address,port,tcp=args.tcp)
        a = DNSRecord.parse(a_pkt)