Ejemplo n.º 1
0
def do_batchmode(infile, cmdline):
    """Execute batch mode on input file supplied to -b"""

    global Prefs, Stats
    print("### resolve.py: Batch Mode file: %s" % Prefs.BATCHFILE)
    print("### command: %s" % ' '.join(cmdline))
    linenum = 0
    for line in open(infile):
        linenum += 1
        line = line.rstrip('\n')
        parts = line.split()
        if len(parts) == 1:
            qname, = parts
            qtype = 'A'
            qclass = 'IN'
        elif len(parts) == 2:
            qname, qtype = parts
            qclass = 'IN'
        elif len(parts) == 3:
            qname, qtype, qclass = parts
        else:
            print("\nERROR input line %d: %s" % (linenum, line))
            continue

        Stats.cnt_cname = 0
        Stats.cnt_deleg = 0
        Stats.cnt_query1 = 0
        Stats.cnt_query2 = 0
        Stats.cnt_fail = 0
        Stats.cnt_tcp = 0
        print("\n### INPUT: %s, %s, %s" % (qname, qtype, qclass))
        query = Query(qname, qtype, qclass, minimize=Prefs.MINIMIZE)
        starting_zone = closest_zone(query.qname)
        print("### Query: %s" % query)
        print("### Starting at zone: %s" % starting_zone)
        resolve_name(query, starting_zone, addResults=query)
        if Prefs.VERBOSE:
            print('')
        query.print_full_answer()

    print("\n### End Batch Mode.")
    return
Ejemplo n.º 2
0
def badass(RootZone):

    with open(sys.argv[1]) as f:
        for line in f:
            parts = line.split()
            if parts[0].find("print") != -1:
                printCache()
            if parts[0].find("resolve") != -1:
                qname = parts[1]
                qtype = parts[2]
                qclass = 'IN'
            elif parts[0].find("quit") != -1:
                sys.exit(0)
            else:
                pass
                continue
            query = Query(qname, qtype, qclass, minimize=False)
            starting_zone = closest_zone(query.qname)
            resolve_name(query, starting_zone, addResults=query)
            query.print_full_answer()
    return
Ejemplo n.º 3
0
def do_batchmode(RootZone):
    """Execute batch mode on input file supplied to -b"""

    global Prefs, Stats
    print("### resolve.py: Batch Mode file: %s" % Prefs.BATCHFILE)
    linenum = 0
    for line in open(Prefs.BATCHFILE):
        linenum += 1
        line = line.rstrip('\n')
        parts = line.split()
        if len(parts) == 1:
            qname, = parts
            qtype = 'A'
            qclass = 'IN'
        elif len(parts) == 2:
            qname, qtype = parts
            qclass = 'IN'
        elif len(parts) == 3:
            qname, qtype, qclass = parts
        else:
            print("\nERROR input line %d: %s" % (linenum, line))
            continue

        Stats.cnt_cname = 0
        Stats.cnt_deleg = 0
        Stats.cnt_query1 = 0
        Stats.cnt_query2 = 0
        Stats.cnt_fail = 0
        Stats.cnt_tcp = 0
        print("\n### INPUT: %s, %s, %s" % (qname, qtype, qclass))
        query = Query(qname, qtype, qclass, minimize=Prefs.MINIMIZE)
        starting_zone = closest_zone(query.qname)
        print("### Query: %s" % query)
        print("### Starting at zone: %s" % starting_zone)
        resolve_name(query, starting_zone, addResults=query)
        query.print_full_answer()

    print("\n### End Batch Mode.")
    return
Ejemplo n.º 4
0
        qname, qtype = args
        qclass = 'IN'
    elif numargs == 3:
        qname, qtype, qclass = args
    else:
        usage()

    return (qname, qtype, qclass)


if __name__ == '__main__':

    random.seed(os.urandom(64))
    qname, qtype, qclass = process_args(sys.argv[1:])
    RootZone = get_root_zone()

    if Prefs.BATCHFILE:
        do_batchmode(infile=Prefs.BATCHFILE, cmdline=sys.argv)
        sys.exit(0)
    else:
        query = Query(qname, qtype, qclass, minimize=Prefs.MINIMIZE)
        resolve_name(query, RootZone, addResults=query)
        if Prefs.VERBOSE:
            print('')
        query.print_full_answer()

        if Prefs.DEBUG or Prefs.STATS:
            print_stats()

        sys.exit(exit_status(query))
Ejemplo n.º 5
0
        qclass = 'IN'
    elif numargs == 2:
        qname, qtype = args
        qclass = 'IN'
    elif numargs == 3:
        qname, qtype, qclass = args
    else:
        usage()

    return (qname, qtype, qclass)


if __name__ == '__main__':

    random.seed(os.urandom(64))
    qname, qtype, qclass = process_args(sys.argv[1:])
    RootZone = get_root_zone()

    if Prefs.BATCHFILE:
        do_batchmode(RootZone)
        sys.exit(0)
    else:
        query = Query(qname, qtype, qclass, minimize=Prefs.MINIMIZE)
        resolve_name(query, RootZone, addResults=query)
        query.print_full_answer()

        if Prefs.DEBUG or Prefs.STATS:
            print_stats()

        sys.exit(exit_status(query))