From a09342ed2af99e49dfa93b45122ad5182aaf0fc4 Mon Sep 17 00:00:00 2001 From: Donald Zou Date: Mon, 15 Dec 2025 16:25:13 +0800 Subject: [PATCH] Added fallback when instance is completely disconnected from internet --- src/modules/Utilities.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/modules/Utilities.py b/src/modules/Utilities.py index 0ba24066..d2d61c99 100644 --- a/src/modules/Utilities.py +++ b/src/modules/Utilities.py @@ -18,10 +18,18 @@ def GetRemoteEndpoint() -> str: @return: """ import socket - with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s: - s.connect(("1.1.1.1", 80)) # Connecting to a public IP + try: + with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s: + s.connect(("1.1.1.1", 80)) # Connecting to a public IP wgd_remote_endpoint = s.getsockname()[0] return str(wgd_remote_endpoint) + except (socket.error, OSError): + pass + try: + return socket.gethostbyname(socket.gethostname()) + except (socket.error, OSError): + pass + return "127.0.0.1" def StringToBoolean(value: str):