Fail gracefully in case of no open ports on Windows

This commit is contained in:
Daniel Goldberg 2018-04-02 16:49:18 +03:00
parent f37c3aaa2c
commit 99b22cfa56
1 changed files with 1 additions and 1 deletions

View File

@ -139,7 +139,7 @@ def check_tcp_ports(ip, ports, timeout=DEFAULT_TIMEOUT, get_banner=False):
"On host %s discovered the following ports %s" % "On host %s discovered the following ports %s" %
(str(ip), ",".join([str(s[0]) for s in connected_ports_sockets]))) (str(ip), ",".join([str(s[0]) for s in connected_ports_sockets])))
banners = [] banners = []
if get_banner: if get_banner and (len(connected_ports_sockets) != 0):
readable_sockets, _, _ = select.select([s[1] for s in connected_ports_sockets], [], [], 0) readable_sockets, _, _ = select.select([s[1] for s in connected_ports_sockets], [], [], 0)
# read first BANNER_READ bytes # read first BANNER_READ bytes
banners = [sock.recv(BANNER_READ) if sock in readable_sockets else "" banners = [sock.recv(BANNER_READ) if sock in readable_sockets else ""