def get_external_ip():
 try:
  r = requests.get(METADATA_NETWORK_INTERFACE_URL, headers={'Metadata-Flavor': 'Google'}, timeout=2)
  return r.text
 except requests.RequestException:
  logging.info('Metadata server could not be reached, assuming local.')
  return 'localhost'

def get_external_ip ( ) : try : r = requests . get ( METADATA_NETWORK_INTERFACE_URL , headers = { 'Metadata-Flavor' : 'Google' } , timeout = 2 ) return r . text except requests . RequestException : logging . info ( 'Metadata server could not be reached, assuming local.' ) return 'localhost'
returns a deferred which will be called with the wan ip address retreived through upnp .