Python socket.AI_V4MAPPED Examples
The following are 5
code examples of socket.AI_V4MAPPED().
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
.
![](https://www.programcreek.com/common/static/images/search.png)
Example #1
Source File: server.py From teleport with Apache License 2.0 | 6 votes |
def address_info(self): conf_refresh_interval = get_config_parameter('ADDRESS_INFO_REFRESH_TIME') if not self._address_info or (datetime.now() - self._address_info_resolved_time).seconds > conf_refresh_interval: # converts addresses tuple to list and adds a 6th parameter for availability (None = not checked, True = available, False=not available) and a 7th parameter for the checking time addresses = None try: if self.ipc: addresses = [(socket.AF_UNIX, socket.SOCK_STREAM, 0, None, self.host, None)] else: if self.mode == IP_V4_ONLY: addresses = socket.getaddrinfo(self.host, self.port, socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP, socket.AI_ADDRCONFIG | socket.AI_V4MAPPED) elif self.mode == IP_V6_ONLY: addresses = socket.getaddrinfo(self.host, self.port, socket.AF_INET6, socket.SOCK_STREAM, socket.IPPROTO_TCP, socket.AI_ADDRCONFIG | socket.AI_V4MAPPED) else: addresses = socket.getaddrinfo(self.host, self.port, socket.AF_UNSPEC, socket.SOCK_STREAM, socket.IPPROTO_TCP, socket.AI_ADDRCONFIG | socket.AI_V4MAPPED) except (socket.gaierror, AttributeError): pass if not addresses: # if addresses not found or raised an exception (for example for bad flags) tries again without flags try: if self.mode == IP_V4_ONLY: addresses = socket.getaddrinfo(self.host, self.port, socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP) elif self.mode == IP_V6_ONLY: addresses = socket.getaddrinfo(self.host, self.port, socket.AF_INET6, socket.SOCK_STREAM, socket.IPPROTO_TCP) else: addresses = socket.getaddrinfo(self.host, self.port, socket.AF_UNSPEC, socket.SOCK_STREAM, socket.IPPROTO_TCP) except socket.gaierror: pass if addresses: self._address_info = [list(address) + [None, None] for address in addresses] self._address_info_resolved_time = datetime.now() else: self._address_info = [] self._address_info_resolved_time = datetime(MINYEAR, 1, 1) # smallest date if log_enabled(BASIC): for address in self._address_info: log(BASIC, 'address for <%s> resolved as <%r>', self, address[:-2]) return self._address_info
Example #2
Source File: server.py From teleport with Apache License 2.0 | 5 votes |
def address_info(self): conf_refresh_interval = get_config_parameter('ADDRESS_INFO_REFRESH_TIME') if not self._address_info or (datetime.now() - self._address_info_resolved_time).seconds > conf_refresh_interval: # converts addresses tuple to list and adds a 6th parameter for availability (None = not checked, True = available, False=not available) and a 7th parameter for the checking time addresses = None try: if self.ipc: addresses = [(socket.AF_UNIX, socket.SOCK_STREAM, 0, None, self.host, None)] else: addresses = socket.getaddrinfo(self.host, self.port, socket.AF_UNSPEC, socket.SOCK_STREAM, socket.IPPROTO_TCP, socket.AI_ADDRCONFIG | socket.AI_V4MAPPED) except (socket.gaierror, AttributeError): pass if not addresses: # if addresses not found or raised an exception (for example for bad flags) tries again without flags try: addresses = socket.getaddrinfo(self.host, self.port, socket.AF_UNSPEC, socket.SOCK_STREAM, socket.IPPROTO_TCP) except socket.gaierror: pass if addresses: self._address_info = [list(address) + [None, None] for address in addresses] self._address_info_resolved_time = datetime.now() else: self._address_info = [] self._address_info_resolved_time = datetime(MINYEAR, 1, 1) # smallest date if log_enabled(BASIC): for address in self._address_info: log(BASIC, 'address for <%s> resolved as <%r>', self, address[:-2]) return self._address_info
Example #3
Source File: server.py From teleport with Apache License 2.0 | 5 votes |
def address_info(self): conf_refresh_interval = get_config_parameter('ADDRESS_INFO_REFRESH_TIME') if not self._address_info or (datetime.now() - self._address_info_resolved_time).seconds > conf_refresh_interval: # converts addresses tuple to list and adds a 6th parameter for availability (None = not checked, True = available, False=not available) and a 7th parameter for the checking time addresses = None try: if self.ipc: addresses = [(socket.AF_UNIX, socket.SOCK_STREAM, 0, None, self.host, None)] else: if self.mode == IP_V4_ONLY: addresses = socket.getaddrinfo(self.host, self.port, socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP, socket.AI_ADDRCONFIG | socket.AI_V4MAPPED) elif self.mode == IP_V6_ONLY: addresses = socket.getaddrinfo(self.host, self.port, socket.AF_INET6, socket.SOCK_STREAM, socket.IPPROTO_TCP, socket.AI_ADDRCONFIG | socket.AI_V4MAPPED) else: addresses = socket.getaddrinfo(self.host, self.port, socket.AF_UNSPEC, socket.SOCK_STREAM, socket.IPPROTO_TCP, socket.AI_ADDRCONFIG | socket.AI_V4MAPPED) except (socket.gaierror, AttributeError): pass if not addresses: # if addresses not found or raised an exception (for example for bad flags) tries again without flags try: if self.mode == IP_V4_ONLY: addresses = socket.getaddrinfo(self.host, self.port, socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP) elif self.mode == IP_V6_ONLY: addresses = socket.getaddrinfo(self.host, self.port, socket.AF_INET6, socket.SOCK_STREAM, socket.IPPROTO_TCP) else: addresses = socket.getaddrinfo(self.host, self.port, socket.AF_UNSPEC, socket.SOCK_STREAM, socket.IPPROTO_TCP) except socket.gaierror: pass if addresses: self._address_info = [list(address) + [None, None] for address in addresses] self._address_info_resolved_time = datetime.now() else: self._address_info = [] self._address_info_resolved_time = datetime(MINYEAR, 1, 1) # smallest date if log_enabled(BASIC): for address in self._address_info: log(BASIC, 'address for <%s> resolved as <%r>', self, address[:-2]) return self._address_info
Example #4
Source File: ofpmanager.py From vlcp with Apache License 2.0 | 5 votes |
def getconnectionsbyendpointname(self, name, vhost = '', timeout = 30): "Get connection by endpoint name (Domain name, IP or IPv6 address)" # Resolve the name if not name: endpoint = '' return await self.getconnectionbyendpoint(endpoint, vhost) else: request = (name, 0, socket.AF_UNSPEC, socket.SOCK_STREAM, socket.IPPROTO_TCP, socket.AI_ADDRCONFIG | socket.AI_V4MAPPED) # Resolve hostname await self.apiroutine.wait_for_send(ResolveRequestEvent(request)) timeout_, ev, m = await self.apiroutine.wait_with_timeout(timeout, ResolveResponseEvent.createMatcher(request)) if timeout_: # Resolve is only allowed through asynchronous resolver #try: # self.addrinfo = socket.getaddrinfo(self.hostname, self.port, socket.AF_UNSPEC, socket.SOCK_DGRAM if self.udp else socket.SOCK_STREAM, socket.IPPROTO_UDP if self.udp else socket.IPPROTO_TCP, socket.AI_ADDRCONFIG|socket.AI_NUMERICHOST) #except: raise IOError('Resolve hostname timeout: ' + name) else: if hasattr(ev, 'error'): raise IOError('Cannot resolve hostname: ' + name) resp = ev.response for r in resp: raddr = r[4] if isinstance(raddr, tuple): # Ignore port endpoint = raddr[0] else: # Unix socket? This should not happen, but in case... endpoint = raddr r = await self.getconnectionsbyendpoint(endpoint, vhost) if r is not None: return r return None
Example #5
Source File: ovsdbmanager.py From vlcp with Apache License 2.0 | 5 votes |
def getconnectionsbyendpointname(self, name, vhost = '', timeout = 30): "Get connection by endpoint name (Domain name, IP or IPv6 address)" # Resolve the name if not name: endpoint = '' return await self.getconnectionbyendpoint(endpoint, vhost) else: request = (name, 0, socket.AF_UNSPEC, socket.SOCK_STREAM, socket.IPPROTO_TCP, socket.AI_ADDRCONFIG | socket.AI_V4MAPPED) # Resolve hostname await self.apiroutine.wait_for_send(ResolveRequestEvent(request)) timeout_, ev, _ = await self.apiroutine.wait_with_timeout(timeout, ResolveResponseEvent.createMatcher(request)) if timeout_: # Resolve is only allowed through asynchronous resolver #try: # self.addrinfo = socket.getaddrinfo(self.hostname, self.port, socket.AF_UNSPEC, socket.SOCK_DGRAM if self.udp else socket.SOCK_STREAM, socket.IPPROTO_UDP if self.udp else socket.IPPROTO_TCP, socket.AI_ADDRCONFIG|socket.AI_NUMERICHOST) #except: raise IOError('Resolve hostname timeout: ' + name) else: if hasattr(ev, 'error'): raise IOError('Cannot resolve hostname: ' + name) resp = ev.response for r in resp: raddr = r[4] if isinstance(raddr, tuple): # Ignore port endpoint = raddr[0] else: # Unix socket? This should not happen, but in case... endpoint = raddr r = await self.getconnectionsbyendpoint(endpoint, vhost) if r is not None: return r