Oppertunistic wait

This commit is contained in:
Daniel Goldberg 2017-11-12 18:06:13 +02:00
parent 7fc25adf47
commit 7a523bdd75
1 changed files with 10 additions and 2 deletions

View File

@ -117,6 +117,13 @@ def check_tcp_ports(ip, ports, timeout=DEFAULT_TIMEOUT, get_banner=False):
good_ports.append((port, sock)) good_ports.append((port, sock))
if len(good_ports) != 0: if len(good_ports) != 0:
read_sockets, write_sockets, _ = \
select.select(
[s[1] for s in good_ports],
[s[1] for s in good_ports],
[s[1] for s in good_ports],
timeout) # wait max timeout
if len(write_sockets) != len(good_ports):
time.sleep(timeout) time.sleep(timeout)
read_sockets, write_sockets, _ = \ read_sockets, write_sockets, _ = \
select.select( select.select(
@ -124,6 +131,7 @@ def check_tcp_ports(ip, ports, timeout=DEFAULT_TIMEOUT, get_banner=False):
[s[1] for s in good_ports], [s[1] for s in good_ports],
[s[1] for s in good_ports], [s[1] for s in good_ports],
0) # no timeout because we've already slept 0) # no timeout because we've already slept
connected_ports_sockets = [x for x in good_ports if x[1] in write_sockets] connected_ports_sockets = [x for x in good_ports if x[1] in write_sockets]
LOG.debug( LOG.debug(
"On host %s discovered the following ports %s" % "On host %s discovered the following ports %s" %