コード例 #1
0
async def test_resolver():
    dns.setup_resolver(ns)

    iplist = await dns.query('google.com', 'A')
    assert len(iplist) > 0

    iplist = await dns.query('google.com', 'AAAA')
    assert len(iplist) > 0

    iplist = await dns.query('google.com', 'NS')
    assert len(iplist) > 0

    iplist = await dns.query('google.com', 'CNAME')
    assert iplist is None

    iplist = await dns.query('www.blogger.com', 'CNAME')
    assert len(iplist) > 0
コード例 #2
0
async def test_resolver():
    dns.setup_resolver(ns)

    iplist = await dns.query('google.com', 'A')
    assert len(iplist) > 0

    iplist = await dns.query('google.com', 'AAAA')
    assert len(iplist) > 0

    iplist = await dns.query('google.com', 'NS')
    assert len(iplist) > 0

    with pytest.raises(aiodns.error.DNSError):
        iplist = await dns.query('google.com', 'CNAME')
        assert iplist is None

    iplist = await dns.query('www.blogger.com', 'CNAME')
    assert len(iplist) > 0
コード例 #3
0
ARGS = argparse.ArgumentParser(description='CoCrawler dns fetcher')
ARGS.add_argument('--config', action='append')
ARGS.add_argument('--configfile', action='store')
ARGS.add_argument('--no-confighome', action='store_true')
ARGS.add_argument('--type', default='A')
ARGS.add_argument('hosts', nargs='+', help='list of hostnames to query')

args = ARGS.parse_args()

config.config(args.configfile, args.config, confighome=not args.no_confighome)

ns = config.read('Fetcher', 'Nameservers')
if not isinstance(ns, list):
    ns = [ns]

dns.setup_resolver(ns)
print('set nameservers to', ns)


async def main(hosts):
    for host in hosts:
        try:
            result = await dns.query(host, args.type)
            print(host, result)
        except Exception as e:
            result = None
            print('saw exception', e, 'but ignoring it')


loop = asyncio.get_event_loop()