diff --git a/src/diagnosers/10-ip.py b/src/diagnosers/10-ip.py index 247c486fc..832b0fa7a 100644 --- a/src/diagnosers/10-ip.py +++ b/src/diagnosers/10-ip.py @@ -203,7 +203,7 @@ class MyDiagnoser(Diagnoser): def get_public_ip(self, protocol=4): - # FIXME - TODO : here we assume that DNS resolution for ip.yunohost.org is working + # FIXME - TODO : The best would be to make it configurable # but if we want to be able to diagnose DNS resolution issues independently from # internet connectivity, we gotta rely on fixed IPs first.... @@ -214,12 +214,20 @@ class MyDiagnoser(Diagnoser): protocol ) - url = "https://ip%s.yunohost.org" % ("6" if protocol == 6 else "") + ip_url_yunohost_tab = ["https://ip%s.yunohost.org" % (protocol if protocol != 4 else ""), "https://0-ip%s.yunohost.org" % (protocol if protocol != 4 else "")] - try: - return download_text(url, timeout=30).strip() - except Exception as e: - protocol = str(protocol) - e = str(e) - self.logger_debug(f"Could not get public IPv{protocol} : {e}") - return None + # Check URLS + for url in ip_url_yunohost_tab: + try: + return download_text(url, timeout=10).strip() + except Exception as e: + self.logger_debug( + "Could not get public IPv%s from %s : %s" % (str(protocol), url, str(e)) + ) + + return None + + + +def main(args, env, loggers): + return MyDiagnoser(args, env, loggers).diagnose() diff --git a/src/utils/network.py b/src/utils/network.py index 28dcb204c..6eb8e57e2 100644 --- a/src/utils/network.py +++ b/src/utils/network.py @@ -53,7 +53,7 @@ def get_public_ip(protocol=4): def get_public_ip_from_remote_server(protocol=4): - """Retrieve the public IP address from ip.yunohost.org""" + """Retrieve the public IP address from ip.yunohost.org or another Server""" # We can know that ipv6 is not available directly if this file does not exists if protocol == 6 and not os.path.exists("/proc/net/if_inet6"): @@ -81,14 +81,19 @@ def get_public_ip_from_remote_server(protocol=4): ) return None - url = "https://ip%s.yunohost.org" % (protocol if protocol != 4 else "") - logger.debug("Fetching IP from %s " % url) + ip_url_yunohost_tab = ["https://ip%s.yunohost.org" % (protocol if protocol != 4 else ""), "https://0-ip%s.yunohost.org" % (protocol if protocol != 4 else "")] - try: - return download_text(url, timeout=30).strip() - except Exception as e: - logger.debug(f"Could not get public IPv{protocol} : {e}") - return None + # Check URLS + for url in ip_url_yunohost_tab: + logger.debug("Fetching IP from %s " % url) + try: + return download_text(url, timeout=30).strip() + except Exception as e: + logger.debug( + "Could not get public IPv%s from %s : %s" % (str(protocol), url, str(e)) + ) + + return None def get_network_interfaces():