code: def get_wan_ip(n=0):
      
  
      if n == 2:
          try:
              ip = myip()
              ip = extract_ip(ip)
              if is_ip_valid(ip):
                  return ip
          except Exception as e:
              print(str(e))
              return None
  
      # Fail-safe: use centralized server for IP lookup.
      from pyp2p.net import forwarding_servers
      for forwarding_server in forwarding_servers:
          url = "http://" + forwarding_server["addr"] + ":"
          url += str(forwarding_server["port"])
          url += forwarding_server["url"]
          url += "?action=get_wan_ip"
          try:
              r = urlopen(url, timeout=5)
              response = r.read().decode("utf-8")
              response = extract_ip(response)
              if is_ip_valid(response):
                  return response
          except Exception as e:
              print(str(e))
              continue
  
      time.sleep(1)
      return get_wan_ip(n + 1)
docs: That IP module sucks. Occasionally it returns an IP address behind
      cloudflare which probably happens when cloudflare tries to proxy your web
      request because it thinks you're trying to DoS. It's better if we just run
      our own infrastructure.