From 1066e2250f0669bab81bc146c1c34d73723a0863 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Sun, 25 Jun 2023 10:35:31 +0800 Subject: [PATCH] bugfix --- appPublic/uni_outip.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) mode change 100644 => 100755 appPublic/uni_outip.py diff --git a/appPublic/uni_outip.py b/appPublic/uni_outip.py old mode 100644 new mode 100755 index 0950c45..260e2dd --- a/appPublic/uni_outip.py +++ b/appPublic/uni_outip.py @@ -6,23 +6,32 @@ from appPublic.ipgetter import IPgetter from multiprocessing import Process, Pipe def pmp_get_external_ip(): - return pmp.get_public_address() + try: + return pmp.get_public_address() + except: + return None def upnp_get_external_ip(): - igd = upnpclient.discover()[0] - s_names = [ n for n in igd.service_map.keys() if 'WAN' in n and 'Conn' in n] - upnp = igd.service_map[s_names[0]] - x = upnp.GetExternalIPAddress() - return x.get('NewExternalIPAddress', None) + try: + igd = upnpclient.discover()[0] + s_names = [ n for n in igd.service_map.keys() if 'WAN' in n and 'Conn' in n] + upnp = igd.service_map[s_names[0]] + x = upnp.GetExternalIPAddress() + return x.get('NewExternalIPAddress', None) + except: + return None def ipgetter_get_external_ip(): getter = IPgetter() ip = None while ip is None: - ip = getter.get_external_ip() + try: + ip = getter.get_external_ip() + except: + ip = None if ip: return ip - time.sleep(0.5) + time.sleep(0.1) def get_external_ip(): ip = pmp_get_external_ip()