@ -57,14 +57,17 @@ def set_node_ip(node):
" Unable to find public IP of server " )
def key scan( ip , port = 22 , timeout = 60 ) :
def node scan( ip , port = 22 , timeout = 60 , gather_hostkeys = True ) :
'''
Scan the IP address for public SSH keys .
Keys are returned formatted as : " <type> <base64_string> "
'''
if ' fake ' in ip :
return [ ' ssh-rsa FAKEKEY ' ]
if gather_hostkeys :
return [ ' ssh-rsa FAKEKEY ' ]
else :
return [ ]
addrinfo = socket . getaddrinfo ( ip , port ) [ 0 ]
family = addrinfo [ 0 ]
@ -73,16 +76,18 @@ def keyscan(ip, port=22, timeout=60):
keys = [ ]
key = None
for count in iterate_timeout (
timeout , exceptions . SSHTimeoutException , " ssh access " ) :
timeout , exceptions . ConnectionTimeoutException ,
" connection on port %s " % port ) :
sock = None
t = None
try :
sock = socket . socket ( family , socket . SOCK_STREAM )
sock . settimeout ( timeout )
sock . connect ( sockaddr )
t = paramiko . transport . Transport ( sock )
t . start_client ( timeout = timeout )
key = t . get_remote_server_key ( )
if gather_hostkeys :
t = paramiko . transport . Transport ( sock )
t . start_client ( timeout = timeout )
key = t . get_remote_server_key ( )
break
except socket . error as e :
if e . errno not in [ errno . ECONNREFUSED , errno . EHOSTUNREACH , None ] :