def isInKnownHosts(host, pubKey, options):
 keyType = common.getNS(pubKey)[0]
 retVal = 0
 if ((not options['known-hosts']) and (not os.path.exists(os.path.expanduser('~/.ssh/')))):
  print 'Creating ~/.ssh directory...'
  os.mkdir(os.path.expanduser('~/.ssh'))
 kh_file = (options['known-hosts'] or '~/.ssh/known_hosts')
 try:
  known_hosts = open(os.path.expanduser(kh_file))
 except IOError:
  return 0
 for line in known_hosts.xreadlines():
  split = line.split()
  if (len(split) < 3):
   continue
  (hosts, hostKeyType, encodedKey) = split[:3]
  if (host not in hosts.split(',')):
   continue
  if (hostKeyType != keyType):
   continue
  try:
   decodedKey = base64.decodestring(encodedKey)
  except:
   continue
  if (decodedKey == pubKey):
   return 1
  else:
   retVal = 2
 return retVal

def isInKnownHosts ( host , pubKey , options ) : keyType = common . getNS ( pubKey ) [ 0 ] retVal = 0 if ( ( not options [ 'known-hosts' ] ) and ( not os . path . exists ( os . path . expanduser ( '~/.ssh/' ) ) ) ) : print 'Creating ~/.ssh directory...' os . mkdir ( os . path . expanduser ( '~/.ssh' ) ) kh_file = ( options [ 'known-hosts' ] or '~/.ssh/known_hosts' ) try : known_hosts = open ( os . path . expanduser ( kh_file ) ) except IOError : return 0 for line in known_hosts . xreadlines ( ) : split = line . split ( ) if ( len ( split ) < 3 ) : continue ( hosts , hostKeyType , encodedKey ) = split [ : 3 ] if ( host not in hosts . split ( ',' ) ) : continue if ( hostKeyType != keyType ) : continue try : decodedKey = base64 . decodestring ( encodedKey ) except : continue if ( decodedKey == pubKey ) : return 1 else : retVal = 2 return retVal
checks to see if host is in the known_hosts file for the user .