python-paramiko初體驗

什麼pexpect、pxshll在paramiko面前都是浮雲,重要的是paramiko支持windows。html

小試牛刀python

import paramiko

paramiko.util.log_to_file('ssh.log') # sets up logging
username = 'root'
password = '123456'
command = 'ls -l'
client = paramiko.SSHClient()
#client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(hostname='192.168.3.100',port=22, username=username, password=password,pkey=None,key_filename=None,timeout=None,allow_agent=False,look_for_keys=False,compress=False)
stdin, stdout, stderr = client.exec_command(command)
print stdout.read()

client.close()

輸出結果:windows

C:\Python27\python.exe E:/python/dabao/study/02.py
total 44
-rw-------. 1 root root  1106 Jul 11 05:26 anaconda-ks.cfg
-rw-r--r--. 1 root root 23089 Jul 11 05:26 install.log
-rw-r--r--. 1 root root  6240 Jul 11 05:24 install.log.syslog
drwxr-xr-x. 2 root root  4096 Jul 17 03:24 scripts

Exception in thread Thread-1 (most likely raised during interpreter shutdown):
Process finished with exit code 0

真心是我想要。ssh

下面介紹下他的安裝方法:spa

安裝相關支撐庫:code

      安裝pycrypto:http://www.voidspace.org.uk/python/modules.shtml#pycryptohtm

  因爲個人客戶端是windows,我下載的.exe文件,直接運行安裝
      安裝paramiko,https://pypi.python.org/pypi/paramiko/1.7.7.1
      cmd切換到對應目錄執行:python setup.py install
blog

導入模塊證實安裝成功。ip

相關文章
相關標籤/搜索