def resolve(host, mask=None): """resolve(hostname, [mask] Resolve a hostname to an IPv4 object. An optional mask value may me supplied.""" try: hostname, aliases, addresses = socket.gethostbyname_ex(str(host)) except socket.gaierror, why: raise ValueError, "Unable to resolve host: %s" % (why[1])
def resolve(host, mask=None): """Resolve a hostname to an IPv4 object. An optional mask value may me supplied.""" try: hostname, aliases, addresses = socket.gethostbyname_ex(str(host)) except socket.gaierror as why: raise ValueError("Unable to resolve host: %s" % (why[1])) if addresses: return IPv4(addresses[0], mask) else: raise ValueError("No addresses found.")