mirror of
https://github.com/midoks/mdserver-web.git
synced 2026-10-10 01:39:25 +08:00
Merge pull request #859 from ccbkkb/master
This commit is contained in:
+17
-16
@@ -514,31 +514,32 @@ def checkDomainPanel():
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def getLocalIp():
|
def getLocalIp():
|
||||||
filename = getPanelDir()+'/data/iplist.txt'
|
try:
|
||||||
|
filename = getPanelDir() + '/data/iplist.txt'
|
||||||
try:
|
try:
|
||||||
ipaddress = readFile(filename)
|
ipaddress = readFile(filename)
|
||||||
if not ipaddress or ipaddress == '127.0.0.1':
|
if ipaddress and 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
|
|
||||||
return ipaddress
|
return ipaddress
|
||||||
except Exception as e:
|
except Exception:
|
||||||
cmd = "curl --insecure -6 -sS --connect-timeout 5 -m 60 https://v6r.ipip.net/?format=text"
|
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)
|
ip = execShell(cmd)
|
||||||
result = ip[0].strip()
|
if ip and isinstance(ip, (tuple, list)) and ip[0]:
|
||||||
if result == '':
|
for line in ip[0].splitlines():
|
||||||
return '127.0.0.1'
|
if line.startswith('ip='):
|
||||||
|
result = line[3:].strip()
|
||||||
|
if result:
|
||||||
writeFile(filename, result)
|
writeFile(filename, result)
|
||||||
return result
|
return result
|
||||||
finally:
|
except Exception:
|
||||||
|
continue
|
||||||
|
except Exception:
|
||||||
pass
|
pass
|
||||||
return '127.0.0.1'
|
return '127.0.0.1'
|
||||||
|
|
||||||
|
|
||||||
def inArray(arrays, searchStr):
|
def inArray(arrays, searchStr):
|
||||||
# 搜索数据中是否存在
|
# 搜索数据中是否存在
|
||||||
for key in arrays:
|
for key in arrays:
|
||||||
|
|||||||
Reference in New Issue
Block a user