Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- for host in hosts():
- ssh = paramiko.SSHClient()
- ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- try:
- ssh.connect(host, username=l_user, password=l_password, timeout=1000)
- except paramiko.SSHException:
- print("Connection Failed")
- except paramiko.AuthenticationException:
- raise 259
- except socket.error:
- raise 261
- transport = ssh.get_transport()
- session = transport.open_session()
- session.set_combine_stderr(True)
- session.get_pty()
- for commands in l_commands:
- session = transport.open_session()
- session.set_combine_stderr(True)
- session.get_pty()
- session.exec_command(commands)
- stdin = session.makefile('wb', -1)
- stdout = session.makefile('rb', -1)
- # you have to check if you really need to send password here
- stdin.write(l_password + 'n')
- stdin.flush()
- key_list = []
- for line in stdout.read().splitlines():
- input_line = line
- input_line = input_line.replace(b'[sudo] password for ufitadmin: ', b'')
- key_individual = str(input_line, 'utf-8')
- key_individual = key_individual.replace(
- 'cat: /home/%s/.ssh/authorized_keys: No such file or directory' % user,
- 'No key exists for this user.')
- key_list.append(key_individual)
- # key_list = list(filter(None, key_list))
- # list2 = [x for x in key_list if x]
- global keyDict
- keyDict = {}
- keyDict[host] = key_list
- filterString = "No key exists for this user."
- filteredKeylist = []
- def filteredKeys():
- for key,value in keyDict.items():
- for values in value:
- if values == filterString:
- return key
- filteredKeylist = list(filteredKeys())
- print(filteredKeylist)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement