mirror of
https://github.com/donaldzou/WGDashboard.git
synced 2025-12-16 16:36:17 +00:00
Added fallback when instance is completely disconnected from internet
This commit is contained in:
@@ -18,10 +18,18 @@ def GetRemoteEndpoint() -> str:
|
|||||||
@return:
|
@return:
|
||||||
"""
|
"""
|
||||||
import socket
|
import socket
|
||||||
|
try:
|
||||||
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
|
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
|
||||||
s.connect(("1.1.1.1", 80)) # Connecting to a public IP
|
s.connect(("1.1.1.1", 80)) # Connecting to a public IP
|
||||||
wgd_remote_endpoint = s.getsockname()[0]
|
wgd_remote_endpoint = s.getsockname()[0]
|
||||||
return str(wgd_remote_endpoint)
|
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):
|
def StringToBoolean(value: str):
|
||||||
|
|||||||
Reference in New Issue
Block a user