Recently due to some demand, to engage in http://www.php.cn/wiki/1514.html "target=" _blank ">python, so the weekend engaged. To connect to the server, do some server operations, So install this Paramiko package, directly
Pip Install Paramiko
As a result, the most critical sentence for an error is:
Error:unable to find Vcvarsall.bat
Google lap. Finally find the easiest way to do it. Other installations vs. installing the MinGW are too complicated. Install Pycrypto third-party version because Paramiko relies on Pycrypto, the above error is his error. Install Pycrypto Third-party edition
Pip Install--use-wheel--no-index--find-links=https://github.com/sfbahr/pycrypto-wheels/raw/master/ PYCRYPTO-2.6.1-CP35-NONE-WIN_AMD64.WHL Pycrypto
Once the installation is complete, install Paramiko again. 2. Modify nt.py Install finish the above steps, write a simple program test under
#-*-coding:utf-8-*-#!/usr/bin/python Import paramikoimport threadingdef ssh2 (ip,username,passwd,cmd): try: ssh = Paramiko. Sshclient () ssh.set_missing_host_key_policy (Paramiko. Autoaddpolicy ()) Ssh.connect (ip,22,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 name== ' 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 ()
Run an error.
Importerror:no module named ' Winrandom '
Locate the installation directory for python3.5.
Lib\site-packages\crypto\random\osrng
The nt.py file will
Import Winrandom
Change into
From. Import Winrandom
Run OK again. Very simple