在 main.py 中优化 IP 地址获取逻辑,添加异常处理以确保稳定性
This commit is contained in:
6
main.py
6
main.py
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user