Merge pull request #859 from ccbkkb/master

This commit is contained in:
Mr Chen
2026-03-16 08:35:12 +08:00
committed by GitHub
+17 -16
View File
@@ -514,31 +514,32 @@ def checkDomainPanel():
return False
def getLocalIp():
filename = getPanelDir()+'/data/iplist.txt'
try:
filename = getPanelDir() + '/data/iplist.txt'
try:
ipaddress = readFile(filename)
if not ipaddress or ipaddress == '127.0.0.1':
cmd = "curl --insecure -4 -sS --connect-timeout 5 -m 60 https://v6r.ipip.net/?format=text"
ip = execShell(cmd)
result = ip[0].strip()
if result == '':
raise Exception("ipv4 is empty!")
writeFile(filename, result)
return result
if ipaddress and ipaddress != '127.0.0.1':
return ipaddress
except Exception as e:
cmd = "curl --insecure -6 -sS --connect-timeout 5 -m 60 https://v6r.ipip.net/?format=text"
except Exception:
pass
for flag in ['-4', '-6']:
try:
# 向下兼容 Python 2.7 ~ 3.x,移除 f-string,改用字符串拼接
cmd = "curl --insecure " + flag + " -sS --connect-timeout 5 -m 60 https://speed.cloudflare.com/cdn-cgi/trace" # 使用 speed.cloudflare.com/cdn-cgi/trace 获取公网 IP
ip = execShell(cmd)
result = ip[0].strip()
if result == '':
return '127.0.0.1'
if ip and isinstance(ip, (tuple, list)) and ip[0]:
for line in ip[0].splitlines():
if line.startswith('ip='):
result = line[3:].strip()
if result:
writeFile(filename, result)
return result
finally:
except Exception:
continue
except Exception:
pass
return '127.0.0.1'
def inArray(arrays, searchStr):
# 搜索数据中是否存在
for key in arrays: