| # Prints one of the IP addresses of each of the hostnames given on the |
| # command line. If no arguments are given, returns nonzero. |
| # Only prints addresses that have an active IP route to them. |
| ailist = socket.getaddrinfo(i, TEST_PORT, |
| socket.AF_UNSPEC, socket.SOCK_DGRAM) |
| except socket.error as e: |
| sys.stderr.write('%s: %r: %s\n' % (sys.argv[0], i, e)) |
| for family, _, _, _, addr in ailist: |
| s = socket.socket(family, socket.SOCK_DGRAM) |
| # Datagram sockets don't actually "connect" here. This just |
| # tests whether we have a route that can handle it. |
| except socket.error as e: |
| if e.errno != errno.ENETUNREACH: |
| sys.stderr.write('%s: %r: %s\n' % (sys.argv[0], addr, e)) |