From 0ea0f2d13dbc8333947341aef8c4eadbde53ba66 Mon Sep 17 00:00:00 2001 From: midoks Date: Tue, 23 Aug 2022 07:35:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96getLocalIp=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- class/core/mw.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/class/core/mw.py b/class/core/mw.py index 607354cfc..b2a5bad74 100755 --- a/class/core/mw.py +++ b/class/core/mw.py @@ -650,16 +650,14 @@ def getLocalIp(): try: ipaddress = readFile(filename) if not ipaddress or ipaddress == '127.0.0.1': - raise Exception("ip is empty!") + cmd = "curl -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 - except Exception as e: - cmd = "curl -4 -sS --connect-timeout 5 -m 60 https://v6r.ipip.net/?format=text" - ip = execShell(cmd) - result = ip[0].strip() - if result == '': - raise e - writeFile(filename, result) - return result except Exception as e: cmd = "curl -6 -sS --connect-timeout 5 -m 60 https://v6r.ipip.net/?format=text" ip = execShell(cmd) @@ -668,6 +666,8 @@ def getLocalIp(): return '127.0.0.1' writeFile(filename, result) return result + finally: + pass return '127.0.0.1'