This commit is contained in:
yumoqing 2023-06-24 17:41:17 +08:00
parent 3b96603b30
commit 458de70cbf
2 changed files with 46 additions and 2 deletions

View File

@ -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

41
appPublic/uni_outip.py Normal file
View File

@ -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)