def check_ssh(ip, port, user, key_file, retries=1):
 ssh = paramiko.SSHClient()
 if os.path.isfile('/usr/local/etc/ssh/ssh_known_hosts'):
  try:
   ssh.load_system_host_keys('/usr/local/etc/ssh/ssh_known_hosts')
  except paramiko.hostkeys.InvalidHostKey:
   os.unlink('/usr/local/etc/ssh/ssh_known_hosts')
 for x in range(retries):
  try:
   ssh.connect(ip, port, username=user, key_filename=key_file)
   return True
  except (paramiko.BadHostKeyException, paramiko.SSHException) as e:
   if (hasattr(e, 'message') and (('not found in known_hosts' in e.message) or ('does not match!' in e.message))):
    return fixkey(ip)
  except (paramiko.AuthenticationException, paramiko.SSHException, socket.error) as e:
   print e
 return False

def check_ssh ( ip , port , user , key_file , retries = 1 ) : ssh = paramiko . SSHClient ( ) if os . path . isfile ( '/usr/local/etc/ssh/ssh_known_hosts' ) : try : ssh . load_system_host_keys ( '/usr/local/etc/ssh/ssh_known_hosts' ) except paramiko . hostkeys . InvalidHostKey : os . unlink ( '/usr/local/etc/ssh/ssh_known_hosts' ) for x in range ( retries ) : try : ssh . connect ( ip , port , username = user , key_filename = key_file ) return True except ( paramiko . BadHostKeyException , paramiko . SSHException ) as e : if ( hasattr ( e , 'message' ) and ( ( 'not found in known_hosts' in e . message ) or ( 'does not match!' in e . message ) ) ) : return fixkey ( ip ) except ( paramiko . AuthenticationException , paramiko . SSHException , socket . error ) as e : print e return False
returns true if ssh works properly for the passed in parameters .