Merge pull request 'main' (#36) from sangge/mimajingsai:main into main

Reviewed-on: dqy/mimajingsai#36
This commit is contained in:
dqy
2023-11-17 10:07:52 +08:00
16 changed files with 147 additions and 108 deletions

View File

@@ -381,8 +381,17 @@ async def receive_request(i_m: IP_Message):
def get_own_ip() -> str:
ip = os.environ.get("HOST_IP", "IP not set")
return ip
ip = os.environ.get("HOST_IP")
if not ip: # 如果环境变量中没有IP
try:
# 从网卡获取IP
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80)) # 通过连接Google DNS获取IP
ip = s.getsockname()[0]
s.close()
except:
raise ValueError("Unable to get IP")
return str(ip)
# get node list from central server