예제 #1
0
파일: views.py 프로젝트: dragonslice/nxdom
def fetch_dns_lookups(domains):
    keys = [db.Key.from_path('dns_lookup', domain.key().name())
            for domain in domains]
    lookups = db.get(keys)
    for index in range(len(domains) - 1, -1, -1):
        lookup = lookups[index]
        if not lookup:
            domains.pop(index)
            continue
        domain = domains[index]
        domain.updated = lookup.timestamp
        for tld in TOP_LEVEL_DOMAINS:
            value = getattr(lookup, tld, None)
            if isinstance(value, basestring):
                value = reverse_name(value)
            if value:
                setattr(domain, tld, value)
예제 #2
0
def fetch_dns_lookups(domains):
    keys = [
        db.Key.from_path('dns_lookup',
                         domain.key().name()) for domain in domains
    ]
    lookups = db.get(keys)
    for index in range(len(domains) - 1, -1, -1):
        lookup = lookups[index]
        if not lookup:
            domains.pop(index)
            continue
        domain = domains[index]
        domain.updated = lookup.timestamp
        for tld in TOP_LEVEL_DOMAINS:
            value = getattr(lookup, tld, None)
            if isinstance(value, basestring):
                value = reverse_name(value)
            if value:
                setattr(domain, tld, value)
예제 #3
0
def update_dns(lookups, options):
    names_with_tlds = [lookup.key().name() + '.' + tld
                       for lookup in lookups
                       for tld in TOP_LEVEL_DOMAINS]
    results = resolve_parallel(names_with_tlds, options)
    for lookup in lookups:
        display = False
        name = lookup.key().name()
        for tld in TOP_LEVEL_DOMAINS:
            domain_name = name + '.' + tld
            result = results.get(domain_name, 'timeout=%d' % options.timeout)
            if result != 'status=nxdomain':
                setattr(lookup, tld, reverse_name(result))
                display = True
        if display or options.verbose:
            print '%-12s' % name,
            for tld in TOP_LEVEL_DOMAINS:
                value = getattr(lookup, tld, None)
                if not value:
                    print ' ' * len(tld),
                elif value.startswith('status='):
                    print value[7:][:len(tld)],
                elif value.startswith('timeout='):
                    print (value[8:] + '    ')[:len(tld)],
                else:
                    print tld,
            print
    timeouts = []
    for lookup in lookups:
        for tld in TOP_LEVEL_DOMAINS:
            if hasattr(lookup, tld):
                if getattr(lookup, tld).startswith('timeout='):
                    timeouts.append(lookup.key().name() + '.' + tld)
    if timeouts:
        print "timeout=%d for %d domains:" % (options.timeout, len(timeouts)),
        print ' '.join(timeouts)