windos環境python3.5安裝 paramiko
一、執行命令pip install paramiko,情況如下:
C:\Users\ZFH>pip install paramiko
Collecting paramiko
Downloading https://files.pythonhosted.org/packages/cf/ae/94e70d49044ccc234bfdba20114fa947d7ba6eb68a2e452d89b920e62227/paramiko-2.4.2-py2.py3-none-any.whl (193kB)
100% |████████████████████████████████| 194kB 199kB/s
Collecting pyasn1>=0.1.7 (from paramiko)
Downloading https://files.pythonhosted.org/packages/d1/a1/7790cc85db38daa874f6a2e6308131b9953feb1367f2ae2d1123bb93a9f5/pyasn1-0.4.4-py2.py3-none-any.whl (72kB)
100% |████████████████████████████████| 81kB 165kB/s
Collecting cryptography>=1.5 (from paramiko)
Downloading https://files.pythonhosted.org/packages/d3/61/d03d9f3138df0d30f779f04e2fe38ace60e6e478ec0f90eb49a97911df01/cryptography-2.3.1-cp35-cp35m-win_amd64.whl (1.3MB)
100% |████████████████████████████████| 1.3MB 114kB/s
Collecting bcrypt>=3.1.3 (from paramiko)
Downloading https://files.pythonhosted.org/packages/f7/7d/c5a4b87a91a98ce2281169bd3dac334c666f82dfeb138d889720229ba6b6/bcrypt-3.1.4-cp35-cp35m-win_amd64.whl
Collecting pynacl>=1.0.1 (from paramiko)
Downloading https://files.pythonhosted.org/packages/26/bd/6e61346d761b3a6698ccd972e1b319af6f603b68518154b3834ce1892c12/PyNaCl-1.3.0-cp35-cp35m-win_amd64.whl (188kB)
100% |████████████████████████████████| 194kB 99kB/s
Collecting idna>=2.1 (from cryptography>=1.5->paramiko)
Downloading https://files.pythonhosted.org/packages/4b/2a/0276479a4b3caeb8a8c1af2f8e4355746a97fab05a372e4a2c6a6b876165/idna-2.7-py2.py3-none-any.whl (58kB)
100% |████████████████████████████████| 61kB 122kB/s
Collecting asn1crypto>=0.21.0 (from cryptography>=1.5->paramiko)
Downloading https://files.pythonhosted.org/packages/ea/cd/35485615f45f30a510576f1a56d1e0a7ad7bd8ab5ed7cdc600ef7cd06222/asn1crypto-0.24.0-py2.py3-none-any.whl (101kB)
100% |████████████████████████████████| 102kB 71kB/s
Collecting cffi!=1.11.3,>=1.7 (from cryptography>=1.5->paramiko)
Downloading https://files.pythonhosted.org/packages/da/8c/beb1ec9ad61570d082641d0b00df141c102b531547bed382f55bcab25789/cffi-1.11.5-cp35-cp35m-win_amd64.whl (166kB)
100% |████████████████████████████████| 174kB 106kB/s
Requirement already satisfied: six>=1.4.1 in e:\program files\python35\lib\site-packages (from cryptography>=1.5->paramiko) (1.11.0)
Collecting pycparser (from cffi!=1.11.3,>=1.7->cryptography>=1.5->paramiko)
Downloading https://files.pythonhosted.org/packages/68/9e/49196946aee219aead1290e00d1e7fdeab8567783e83e1b9ab5585e6206a/pycparser-2.19.tar.gz (158kB)
100% |████████████████████████████████| 163kB 85kB/s
Installing collected packages: pyasn1, idna, asn1crypto, pycparser, cffi, cryptography, bcrypt, pynacl, paramiko
Running setup.py install for pycparser ... done
Successfully installed asn1crypto-0.24.0 bcrypt-3.1.4 cffi-1.11.5 cryptography-2.3.1 idna-2.7 paramiko-2.4.2 pyasn1-0.4.4 pycparser-2.19 pynacl-1.3.0
You are using pip version 18.0, however version 18.1 is available.
You should consider upgrading via the ‘python -m pip install --upgrade pip‘ command.
以上執行完成後import paramiko測試一下。
>>> import paramiko
>>>
import成功。
寫一個簡單的程序測試下,是否執行成功。
__author__ = ‘ZFH‘ #-*- coding: utf-8 -*- # #!/usr/bin/python import threading import paramiko def ssh2(ip,username,passwd,cmd): try: ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(ip,View Code22,username,passwd,timeout=5) for m in cmd: stdin, stdout, stderr = ssh.exec_command(m) out = stdout.readlines() #在屏幕輸出 for o in out: print(o) print(‘%s\tOK\n‘%(ip)) ssh.close() except: print(‘%s\tError\n‘%(ip)) if username ==‘main‘: cmd = [‘find /home/admin/logs/ -mtime +3 -name \‘*.log.*\‘ -exec rm -rf {} \;‘]#你要執行的命令列表 username = "admin" #用戶名 passwd = "password" #密碼 threads = [] #多線程 ip = "127.0.0.1" print("Begin......") a=threading.Thread(target=ssh2,args=(ip,username,passwd,cmd)) a.start() input()
代碼執行成功。
windos環境python3.5安裝 paramiko