Read catalog
paramiko module Introduction
paramiko module provides a connection-based ssh for remote login and command execution function server upload and download files. This is a third party software package needs to be installed before use
paramiko to use
With kali as experimental subjects, ip: 192.168.41.147
1) Based on sshclient way user names and passwords landing
# ! / Usr / bin / env Python # Coding: utf8 Import paramiko # create sshclient objects SSH = paramiko.SSHClient () # allows trusted hosts are automatically added to the list host_allow, this method must be placed in front of the connect method of ssh.set_missing_host_key_policy (paramiko.AutoAddPolicy ()) # connect method is called connection server ssh.connect (hostname = ' 172.16.32.129 ' , Port = 2323, username = ' the root ' , password = ' 123.com ' ) the while True: input_command = INPUT ( ' >>>: ' ) IF== input_command ' quit ' : BREAK # Run, output to stdout, if the error is on stderr stdin, stdout, stderr = ssh.exec_command (input_command) Result = stdout.read () # Read method reads output IF len (result) == 0: # determination if the output length is equal to 0 indicates an output error Print (stderr.read ()) the else : Print (STR (result, ' UTF-. 8 ' )) ssh.close ( )