我们从Python开源项目中,提取了以下32个代码示例,用于说明如何使用socket.EAI_NONAME。
def is_valid_ip(ip): """Returns true if the given string is a well-formed IP address. Supports IPv4 and IPv6. """ if not ip or '\x00' in ip: # getaddrinfo resolves empty strings to localhost, and truncates # on zero bytes. return False try: res = socket.getaddrinfo(ip, 0, socket.AF_UNSPEC, socket.SOCK_STREAM, 0, socket.AI_NUMERICHOST) return bool(res) except socket.gaierror as e: if e.args[0] == socket.EAI_NONAME: return False raise return True
def check_ip_addr(**kwargs): """ check_ip_addr, Supports IPv4 and IPv6 """ ipaddr = kwargs["ipaddr"] if not ipaddr or '\x00' in ipaddr: return False try: res = socket.getaddrinfo(ipaddr, 0, socket.AF_UNSPEC, socket.SOCK_STREAM, 0, socket.AI_NUMERICHOST) return bool(res) except socket.gaierror: err = sys.exc_info()[1] if err.args[0] == socket.EAI_NONAME: return False raise return True
def check_ip_addr(ipaddr): """ check_ip_addr, Supports IPv4 and IPv6 """ if not ipaddr or '\x00' in ipaddr: return False try: res = socket.getaddrinfo(ipaddr, 0, socket.AF_UNSPEC, socket.SOCK_STREAM, 0, socket.AI_NUMERICHOST) return bool(res) except socket.gaierror: err = sys.exc_info()[1] if err.args[0] == socket.EAI_NONAME: return False raise return True
def is_valid_address(address): """ check ip address, Supports IPv4 and IPv6""" if not address or '\x00' in address: return False try: res = socket.getaddrinfo(address, 0, socket.AF_UNSPEC, socket.SOCK_STREAM, 0, socket.AI_NUMERICHOST) return bool(res) except socket.gaierror: err = sys.exc_info()[1] if err.args[0] == socket.EAI_NONAME: return False raise return True
def check_ip_addr(ipaddr): """check ip address, Supports IPv4 and IPv6""" if not ipaddr or '\x00' in ipaddr: return False try: res = socket.getaddrinfo(ipaddr, 0, socket.AF_UNSPEC, socket.SOCK_STREAM, 0, socket.AI_NUMERICHOST) return bool(res) except socket.gaierror: err = sys.exc_info()[1] if err.args[0] == socket.EAI_NONAME: return False raise
def check_ip_addr(**kwargs): """ check_ip_addr, Supports IPv4 and IPv6""" ipaddr = kwargs["ipaddr"] if not ipaddr or '\x00' in ipaddr: return False try: res = socket.getaddrinfo(ipaddr, 0, socket.AF_UNSPEC, socket.SOCK_STREAM, 0, socket.AI_NUMERICHOST) return bool(res) except socket.gaierror: err = sys.exc_info()[1] if err.args[0] == socket.EAI_NONAME: return False raise return True
def check_ip_addr(ipaddr): """check ip address, Supports IPv4 and IPv6""" if not ipaddr or '\x00' in ipaddr: return False try: res = socket.getaddrinfo(ipaddr, 0, socket.AF_UNSPEC, socket.SOCK_STREAM, 0, socket.AI_NUMERICHOST) return bool(res) except socket.gaierror: err = sys.exc_info()[1] if err.args[0] == socket.EAI_NONAME: return False raise return True
def check_ip_addr(ipaddr): """ check ip address, Supports IPv4 and IPv6 """ if not ipaddr or '\x00' in ipaddr: return False try: res = socket.getaddrinfo(ipaddr, 0, socket.AF_UNSPEC, socket.SOCK_STREAM, 0, socket.AI_NUMERICHOST) return bool(res) except socket.gaierror: err = sys.exc_info()[1] if err.args[0] == socket.EAI_NONAME: return False raise return True
def check_ip_addr(ipaddr): """ check ip address, Supports IPv4 and IPv6 """ if not ipaddr or '\x00' in ipaddr: return False try: res = socket.getaddrinfo(ipaddr, 0, socket.AF_UNSPEC, socket.SOCK_STREAM, 0, socket.AI_NUMERICHOST) return bool(res) except socket.gaierror: err = sys.exc_info()[1] if err.args[0] == socket.EAI_NONAME: return False raise
def is_valid_ip(ip): """Returns true if the given string is a well-formed IP address. Supports IPv4 and IPv6. """ try: res = socket.getaddrinfo(ip, 0, socket.AF_UNSPEC, socket.SOCK_STREAM, 0, socket.AI_NUMERICHOST) return bool(res) except socket.gaierror as e: if e.args[0] == socket.EAI_NONAME: return False raise return True
def test_resolveNumericHost(self): """ L{_resolveIPv6} raises a L{socket.gaierror} (L{socket.EAI_NONAME}) when invoked with a non-numeric host. (In other words, it is passing L{socket.AI_NUMERICHOST} to L{socket.getaddrinfo} and will not accidentally block if it receives bad input.) """ err = self.assertRaises(socket.gaierror, _resolveIPv6, "localhost", 1) self.assertEqual(err.args[0], socket.EAI_NONAME)
def test_resolveNumericService(self): """ L{_resolveIPv6} raises a L{socket.gaierror} (L{socket.EAI_NONAME}) when invoked with a non-numeric port. (In other words, it is passing L{socket.AI_NUMERICSERV} to L{socket.getaddrinfo} and will not accidentally block if it receives bad input.) """ err = self.assertRaises(socket.gaierror, _resolveIPv6, "::1", "http") self.assertEqual(err.args[0], socket.EAI_NONAME)
def _gen_addresses_where_possible(hostname): """Yield IPv4 and IPv6 addresses for `hostname`. A variant of `_gen_addresses` that ignores some resolution failures. The addresses returned are only those that are resolvable at the time this function is called. Specifically the following errors are ignored: +----------------+-----------------------------------------------+ | EAI_ADDRFAMILY | The specified network host does not have any | | | network addresses in the requested address | | | family. | +----------------+-----------------------------------------------+ | EAI_AGAIN | The name server returned a temporary failure | | | indication. Try again later. | +----------------+-----------------------------------------------+ | EAI_FAIL | The name server returned a permanent failure | | | indication. | +----------------+-----------------------------------------------+ | EAI_NODATA | The specified network host exists, but does | | | not have any network addresses defined. | +----------------+-----------------------------------------------+ | EAI_NONAME | The node or service is not known; or both node| | | and service are NULL; or AI_NUMERICSERV was | | | specified and service was not a numeric | | | port-number string. | +----------------+-----------------------------------------------+ Descriptions from getaddrinfo(3). """ try: yield from _gen_addresses(hostname) except socket.gaierror as error: if error.errno in _gen_addresses_where_possible_suppress: # Log this but otherwise suppress/ignore for now. logger.warning("Could not resolve %s: %s", hostname, error) else: raise