There is no dedicated SSH module in Python, which requires a manual installation module. The use of SSH in Python requires openssh, while OpenSSH relies on Paramiko modules, and Paramiko modules rely on Pycrypto modules, so to use SSH in Python, the order of the modules to be installed is pycrypto-〉 Paramiko.
Install OpenSSHOpenSSH Download URL: http://sourceforge.net/projects/sshwindows/, download installation can be.
Installing the Pycrypto module
Pycrypto module Download Address: http://pypi.python.org/pypi/pycrypto/, download installation when the lack of vcvarsall.bat, prompted the need for Visual Studio, online solutions are mostly installed MingW32.
Find the Pycrypto version used in the compiled windows on the Internet, download the URL:
Http://www.voidspace.org.uk/python/modules.shtml#pycrypto
Download the Python version and the corresponding version of the operating system, install it directly.
Note: If it is Win32bit + Python 2.7, download Pycrypto-2.6.win32-py2.7.exe. Installing the Paramiko module
Download the latest version of the Paramiko module from the Http://pypi.python.org/pypi/paramiko URL, unzip it, and go to the uncompressed directory to perform the Python setup.py install installation. using the sample
Use SSH to log on to a remote host to execute commands.
Import Paramiko
def ssh_cmd (ip,port, cmd, User, passwd):
result = ""
Try
SSH = Paramiko. Sshclient ()
Ssh.set_missing_host_key_policy (Paramiko. Autoaddpolicy ())
Ssh.connect (IP, port, user, passwd,timeout=3)
stdin, stdout, stderr =ssh.exec_command (CMD)
result = Stdout.read ()
Ssh.close ()
Except
Print ("Ssh_cmd err.")
return result