diff --git a/vpn_slice/__main__.py b/vpn_slice/__main__.py index 13d0433..4959e3b 100755 --- a/vpn_slice/__main__.py +++ b/vpn_slice/__main__.py @@ -202,18 +202,22 @@ def do_post_connect(env, args): if args.verbose: print("Looking up %d hosts using VPN DNS servers..." % len(args.hosts), file=stderr) for host in args.hosts: - ips = providers.dns.lookup_host( - host, dns_servers=env.dns, search_domains=args.domain, - bind_addresses=env.myaddrs) - if ips is None: - print("WARNING: Lookup for %s on VPN DNS servers failed." % host, file=stderr) + try: + ips = providers.dns.lookup_host( + host, dns_servers=env.dns, search_domains=args.domain, + bind_addresses=env.myaddrs) + except Exception as e: + print("WARNING: Lookup for %s on VPN DNS servers failed:\n\t%s" % (host, e), file=stderr) else: - if args.verbose: - print(" %s = %s" % (host, ', '.join(map(str, ips))), file=stderr) - ip_routes.update(ips) - if args.host_names: - names = names_for(host, args.domain, args.short_names) - host_map.extend((ip, names) for ip in ips) + if ips is None: + print("WARNING: Lookup for %s on VPN DNS servers returned nothing." % host, file=stderr) + else: + if args.verbose: + print(" %s = %s" % (host, ', '.join(map(str, ips))), file=stderr) + ip_routes.update(ips) + if args.host_names: + names = names_for(host, args.domain, args.short_names) + host_map.extend((ip, names) for ip in ips) for ip, aliases in args.aliases.items(): host_map.append((ip, aliases)) diff --git a/vpn_slice/posix.py b/vpn_slice/posix.py index dfd9202..0ca7108 100644 --- a/vpn_slice/posix.py +++ b/vpn_slice/posix.py @@ -47,10 +47,10 @@ def lookup_host(self, hostname, dns_servers, *, bind_addresses=None, search_doma # actually fetch results result = set() for cl in all_cls: - p = subprocess.Popen(cl, stdout=subprocess.PIPE, universal_newlines=True) - output, _ = p.communicate() + p = subprocess.Popen(cl, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) + output, stderr = p.communicate() if p.returncode != 0: - return None + raise subprocess.CalledProcessError(p.returncode, cmd, output=output, stderr=stderr) for line in output.splitlines(): try: result.add(ip_address(line.strip()))