Python socket.EAI_NONAME Examples
The following are 30
code examples of socket.EAI_NONAME().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
socket
, or try the search function
.
Example #1
Source File: netutil.py From tornado-zh with MIT License | 6 votes |
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
Example #2
Source File: netutil.py From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International | 6 votes |
def is_valid_ip(ip: str) -> bool: """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
Example #3
Source File: netutil.py From EventGhost with GNU General Public License v2.0 | 6 votes |
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
Example #4
Source File: netutil.py From python-scripts with GNU General Public License v3.0 | 6 votes |
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
Example #5
Source File: ce_snmp_target_host.py From CloudEngine-Ansible with GNU General Public License v3.0 | 6 votes |
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
Example #6
Source File: ce_sflow.py From CloudEngine-Ansible with GNU General Public License v3.0 | 6 votes |
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
Example #7
Source File: ce_acl_advance.py From CloudEngine-Ansible with GNU General Public License v3.0 | 6 votes |
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
Example #8
Source File: ce_bfd_global.py From CloudEngine-Ansible with GNU General Public License v3.0 | 6 votes |
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
Example #9
Source File: ce_acl.py From CloudEngine-Ansible with GNU General Public License v3.0 | 6 votes |
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
Example #10
Source File: ce_bgp_neighbor_af.py From CloudEngine-Ansible with GNU General Public License v3.0 | 6 votes |
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
Example #11
Source File: ce_aaa_server_host.py From CloudEngine-Ansible with GNU General Public License v3.0 | 6 votes |
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
Example #12
Source File: ce_bfd_session.py From CloudEngine-Ansible with GNU General Public License v3.0 | 6 votes |
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
Example #13
Source File: ce_bgp_af.py From CloudEngine-Ansible with GNU General Public License v3.0 | 6 votes |
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
Example #14
Source File: ce_info_center_global.py From CloudEngine-Ansible with GNU General Public License v3.0 | 6 votes |
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
Example #15
Source File: netutil.py From pySINDy with MIT License | 6 votes |
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
Example #16
Source File: netutil.py From teleport with Apache License 2.0 | 6 votes |
def is_valid_ip(ip: str) -> bool: """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
Example #17
Source File: netutil.py From teleport with Apache License 2.0 | 6 votes |
def is_valid_ip(ip: str) -> bool: """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
Example #18
Source File: netutil.py From teleport with Apache License 2.0 | 6 votes |
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
Example #19
Source File: netutil.py From tornado-zh with MIT License | 6 votes |
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
Example #20
Source File: util.py From pyvpn with The Unlicense | 6 votes |
def is_valid_ip(ip): """Returns true if the given string is a well-formed IP address. Supports IPv4 and IPv6. //取自 tornado """ 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
Example #21
Source File: netutil.py From opendevops with GNU General Public License v3.0 | 6 votes |
def is_valid_ip(ip: str) -> bool: """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
Example #22
Source File: utils.py From open_dnsdb with Apache License 2.0 | 5 votes |
def is_valid_ip_bysocket(ip): 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
Example #23
Source File: tls.py From integrations-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
def create_connection(self): """See: https://github.com/python/cpython/blob/40ee9a3640d702bce127e9877c82a99ce817f0d1/Lib/socket.py#L691""" err = None try: for res in socket.getaddrinfo(self._server, self._port, 0, self._sock_type): af, socktype, proto, canonname, sa = res sock = None try: sock = socket.socket(af, socktype, proto) sock.settimeout(self._timeout) sock.connect(sa) # Break explicitly a reference cycle err = None return sock except socket.error as _: err = _ if sock is not None: sock.close() if err is not None: raise err else: raise socket.error('No valid addresses found, try checking your IPv6 connectivity') # noqa: G except socket.gaierror as e: err_code, message = e.args if err_code == socket.EAI_NODATA or err_code == socket.EAI_NONAME: raise socket.error('Unable to resolve host, check your DNS: {}'.format(message)) # noqa: G raise
Example #24
Source File: test_socket.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def testNI_NAMEREQD(self): # This test may delay for some seconds unreversible_address = "198.51.100.1" try: socket.getnameinfo( (unreversible_address, 80), socket.NI_NAMEREQD) except socket.gaierror, ge: self.failUnlessEqual(ge[0], socket.EAI_NONAME)
Example #25
Source File: test_network.py From maas with GNU Affero General Public License v3.0 | 5 votes |
def test_returns_empty_if_address_does_not_resolve(self): self.patch_getaddrinfo_fail( gaierror(EAI_NONAME, "Name or service not known") ) self.assertEqual(set(), resolve_hostname(factory.make_hostname(), 4))
Example #26
Source File: config.py From maas with GNU Affero General Public License v3.0 | 5 votes |
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
Example #27
Source File: test_socket.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def testNI_NAMEREQD(self): # This test may delay for some seconds unreversible_address = "198.51.100.1" try: socket.getnameinfo( (unreversible_address, 80), socket.NI_NAMEREQD) except socket.gaierror, ge: self.failUnlessEqual(ge[0], socket.EAI_NONAME)
Example #28
Source File: google.py From pghoard with Apache License 2.0 | 5 votes |
def _retry_on_reset(self, request, action): retries = 60 retry_wait = 2 while True: try: return action() except (IncompleteRead, HttpError, ssl.SSLEOFError, socket.timeout, OSError, socket.gaierror) as ex: # Note that socket.timeout and ssl.SSLEOFError inherit from OSError # and the order of handling the errors here needs to be correct if not retries: raise elif isinstance(ex, (IncompleteRead, socket.timeout, ssl.SSLEOFError, BrokenPipeError)): pass # just retry with the same sleep amount elif isinstance(ex, HttpError): # https://cloud.google.com/storage/docs/json_api/v1/status-codes # https://cloud.google.com/storage/docs/exponential-backoff if ex.resp["status"] not in ("429", "500", "502", "503", "504"): # pylint: disable=no-member raise retry_wait = min(10.0, max(1.0, retry_wait * 2) + random.random()) # httplib2 commonly fails with Bad File Descriptor and Connection Reset elif isinstance(ex, OSError) and ex.errno not in [errno.EAGAIN, errno.EBADF, errno.ECONNRESET]: raise # getaddrinfo sometimes fails with "Name or service not known" elif isinstance(ex, socket.gaierror) and ex.errno != socket.EAI_NONAME: raise self.log.warning("%s failed: %s (%s), retrying in %.2fs", action, ex.__class__.__name__, ex, retry_wait) # we want to reset the http connection state in case of error if request and hasattr(request, "http"): request.http.connections.clear() # reset connection cache retries -= 1 time.sleep(retry_wait)
Example #29
Source File: test_socket.py From medicare-demo with Apache License 2.0 | 5 votes |
def testNI_NAMEREQD(self): # This test may delay for some seconds unreversible_address = "198.51.100.1" try: socket.getnameinfo( (unreversible_address, 80), socket.NI_NAMEREQD) except socket.gaierror, ge: self.failUnlessEqual(ge[0], socket.EAI_NONAME)
Example #30
Source File: test_tcp.py From learn_python3_spider with MIT License | 5 votes |
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)