UPnP formatting
This commit is contained in:
parent
86e607c403
commit
35bd5e8595
1 changed files with 9 additions and 8 deletions
|
@ -154,7 +154,9 @@ def _get_local_ips():
|
|||
|
||||
# Delete duplicates
|
||||
local_ips = list(set(local_ips))
|
||||
local_ips = sorted(local_ips, key=lambda a: a.startswith("192"), reverse=True) # Probably we looking for an ip starting with 192
|
||||
|
||||
# Probably we looking for an ip starting with 192
|
||||
local_ips = sorted(local_ips, key=lambda a: a.startswith("192"), reverse=True)
|
||||
|
||||
logging.debug("Found local ips: %s" % local_ips)
|
||||
return local_ips
|
||||
|
@ -312,8 +314,8 @@ def _communicate_with_igd(port=15441,
|
|||
threads = []
|
||||
|
||||
for local_ip in local_ips:
|
||||
thread = gevent.spawn(job, local_ip)
|
||||
threads.append(thread)
|
||||
job_thread = gevent.spawn(job, local_ip)
|
||||
threads.append(job_thread)
|
||||
gevent.sleep(0.1)
|
||||
if any([thread.value for thread in threads]):
|
||||
success = True
|
||||
|
@ -321,7 +323,7 @@ def _communicate_with_igd(port=15441,
|
|||
|
||||
# Wait another 10sec for competition or any positibe result
|
||||
for _ in range(10):
|
||||
all_done = all([thread.value != None for thread in threads])
|
||||
all_done = all([thread.value is not None for thread in threads])
|
||||
any_succeed = any([thread.value for thread in threads])
|
||||
if all_done or any_succeed:
|
||||
break
|
||||
|
@ -355,7 +357,6 @@ def ask_to_close_port(port=15441, desc="UpnpPunch", retries=3, protos=("TCP", "U
|
|||
protos=protos)
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
from gevent import monkey
|
||||
monkey.patch_all()
|
||||
|
@ -364,9 +365,9 @@ if __name__ == "__main__":
|
|||
|
||||
s = time.time()
|
||||
print "Opening port..."
|
||||
print ask_to_open_port(15443, "ZeroNet",protos=["TCP"])
|
||||
print "Done in", time.time()-s
|
||||
print ask_to_open_port(15443, "ZeroNet", protos=["TCP"])
|
||||
print "Done in", time.time() - s
|
||||
|
||||
print "Closing port..."
|
||||
print ask_to_close_port(15443, "ZeroNet", protos=["TCP"])
|
||||
print "Done in", time.time()-s
|
||||
print "Done in", time.time() - s
|
||||
|
|
Loading…
Reference in a new issue