在 main.py 中优化 IP 地址获取逻辑,添加异常处理以确保稳定性

This commit is contained in:
2025-04-10 07:06:41 +08:00
Unverified
parent 5b0cfc0018
commit 9ccfd556f9

View File

@@ -39,7 +39,11 @@ def pseudo_zsh():
username = os.getlogin()
# 获取 IP 地址
ip_address = socket.gethostbyname(socket.gethostname())
try:
hostname = socket.gethostname()
ip_address = socket.gethostbyname_ex(hostname)[2][0] # 获取第一个 IP 地址
except (socket.gaierror, IndexError):
ip_address = "127.0.0.1" # 默认回环地址
# 获取内存信息
memory = psutil.virtual_memory()