def get_external_ip(self, ip_getter: str) -> Iterator[Deferred]: print('Retrieving external IP from {!r} to generate server identifier.'.format(ip_getter)) try: ip = yield self.getPage(ip_getter) ip = IPv4Address(ip.strip()) except AddressValueError as e: print('External IP getter service returned invalid data.\n' 'Please check the "ip_getter" setting in your config.') return except Exception as e: print("Getting external IP failed:", e) return self.ip = ip self.identifier = make_server_identifier(ip, self.port) print('Server public ip address: {}:{}'.format(ip, self.port)) print('Public aos identifier: {}'.format(self.identifier))
async def get_external_ip(self, ip_getter: str) -> Iterator[Deferred]: log.info( 'Retrieving external IP from {!r} to generate server identifier.'.format(ip_getter)) try: async with aiohttp.ClientSession() as session: async with session.get(ip_getter) as response: ip = await response.text() ip = IPv4Address(ip.strip()) except AddressValueError as e: log.warn('External IP getter service returned invalid data.\n' 'Please check the "ip_getter" setting in your config.') return except Exception as e: # pylint: disable=broad-except log.warn("Getting external IP failed: {reason}", reason=e) return self.ip = ip self.identifier = make_server_identifier(ip, self.port) log.info('Server public ip address: {}:{}'.format(ip, self.port)) log.info('Public aos identifier: {}'.format(self.identifier))
def got_external_ip(self, ip): self.ip = ip self.identifier = make_server_identifier(ip, self.port) print 'Server identifier is %s' % self.identifier
def datagramReceived(self, data, address): if self.pyspades_set is None or data != 'HI': return self.pyspades_set.add(make_server_identifier(address[0], address[1]))