New submission from James Lawrie <ja...@silvermouse.net>:
The DNS async resolver allows you to specify a list of nameservers to use, but they are ignored and the system nameservers are used instead. Test code below demonstrating the issue: # cat test.py import dns.asyncresolver import asyncio from pprint import pprint async def main(domains): results = await get_ips_bulk(domains) results = [item for sublist in results for item in sublist] pprint(results) async def get_ips_bulk(domains): output = [get_ips(domain) for domain in domains] return await asyncio.gather(*output, return_exceptions=True) async def get_ips(domain): res = dns.asyncresolver.Resolver() res.nameserver = ["1.1.1.1"] results = [] try: ipv4 = await res.resolve(domain, 'A') for result in ipv4: results.append(['A', domain, result.to_text()]) except: results.append(['A', domain, 'n/a']) try: ipv6 = await res.resolve(domain, 'AAAA') results.append(['AAAA', domain, result.to_text()]) except: results.append(['AAAA', domain, 'n/a']) return results domains = ['python.org'] asyncio.run(main(domains)) It should use 1.1.1.1 as the nameserver but watching tcpdump it's using 8.8.8.8 per /etc/resolv.conf: # tcpdump -n port 53 & [1] 16751 listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes # python3 test.py 19:05:02.750458 IP x.x.x.x.44173 > 8.8.8.8.53: 46143+ A? python.org. (28) 19:05:02.756265 IP 8.8.8.8.53 > x.x.x.x.44173: 46143 1/0/0 A 138.197.63.241 (44) 19:05:02.757392 IP x.x.x.x.37827 > 8.8.8.8.53: 17493+ AAAA? python.org. (28) 19:05:02.765797 IP 8.8.8.8.53 > x.x.x.x.37827: 17493 0/1/0 (115) [['A', 'python.org', '138.197.63.241'], ['AAAA', 'python.org', 'n/a']] # fg tcpdump -n port 53 ^C # grep -P "^nameserver" /etc/resolv.conf nameserver 8.8.8.8 ---------- components: asyncio messages: 405460 nosy: asvetlov, james2, yselivanov priority: normal severity: normal status: open title: dns.asyncresolver ignores nameserver parameter type: behavior versions: Python 3.7 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue45683> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com