From 458de70cbf047ea058a3d05c77012888340cebef Mon Sep 17 00:00:00 2001 From: yumoqing Date: Sat, 24 Jun 2023 17:41:17 +0800 Subject: [PATCH] bugfix --- appPublic/rsawrap.py | 7 +++++-- appPublic/uni_outip.py | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 appPublic/uni_outip.py diff --git a/appPublic/rsawrap.py b/appPublic/rsawrap.py index bf6f2d9..c5433ae 100755 --- a/appPublic/rsawrap.py +++ b/appPublic/rsawrap.py @@ -27,7 +27,7 @@ class RSA: def publickeyFromText(self,text): bd = text.encode(self.coding) - rsa.PublicKey.load_pkcs1(bd) + return rsa.PublicKey.load_pkcs1(bd) def read_publickey(self,fname): with open(fname, 'rb') as pf: @@ -70,7 +70,10 @@ class RSA: r = rsa.verify(bdata, sign, public_key) if r == 'SHA-1': return True - except: + print(f'verify()={r}') + return False + except Exception as e: + print(f'check_sign_bdata() raise Exception{e}') return False diff --git a/appPublic/uni_outip.py b/appPublic/uni_outip.py new file mode 100644 index 0000000..e5b6601 --- /dev/null +++ b/appPublic/uni_outip.py @@ -0,0 +1,41 @@ +import time +from natpmp import NATPMP as pmp +import upnpclient +from ipgetter import IPgetter + +def pmp_get_external_ip(): + return pmp.get_public_address() + +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) + +def ipgetter_get_external_ip(): + getter = IPgetter() + ip = None + while ip is None: + ip = getter.get_external_ip() + if ip: + return ip + time.sleep(0.5) + +def get_external_ip(): + ip = pmp_get_external_ip() + if ip: + return ip + ip = upnp_get_external_ip() + if ip: + return ip + return ipgetter_get_external_ip() + +def run(): + while True: + ip = get_external_ip() + if ip: + print(ip) + time.sleep(10) + +