|
批量登录服务器
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
| #!/usr/bin/env python
#-*- coding: utf-8 -*-
import paramiko
import threading
def 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)
# stdin.write("Y") #简单交互,输入 ‘Y’
out = stdout.readlines()
#屏幕输出
for o in out:
print o,
print '%s\tOK\n'%(ip)
ssh.close()
except :
print '%s\tError\n'%(ip)
__name__=='__main__':
cmd = ['cal','echo hello!']#你要执行的命令列表
username = "root" #用户名
passwd = "flying" #密码
threads = [] #多线程
print "Begin......"
for i in range(62,69):
ip = '110.10.221.'+str(i)
a=threading.Thread(target=ssh2,args=(ip,username,passwd,cmd))
a.start()
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| Begin......
January 2016
Su Mo Tu We Th Fr Sa
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
hello!
110.10.221.62 OK
110.10.221.68 Error
110.10.221.67 Error
110.10.221.66 Error
110.10.221.63 Error
110.10.221.65 Error
110.10.221.64 Error
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
| Traceback (most recent call last):
File "pl.py", line 4, in <module>
import paramiko
File "/usr/lib/python2.6/site-packages/paramiko-1.16.0-py2.6.egg/paramiko/__init__.py", line 30, in <module>
from paramiko.transport import SecurityOptions, Transport
File "/usr/lib/python2.6/site-packages/paramiko-1.16.0-py2.6.egg/paramiko/transport.py", line 50, in <module>
from paramiko.dsskey import DSSKey
File "/usr/lib/python2.6/site-packages/paramiko-1.16.0-py2.6.egg/paramiko/dsskey.py", line 26, in <module>
from Crypto.PublicKey import DSA
File "/usr/lib64/python2.6/site-packages/Crypto/PublicKey/DSA.py", line 88, in <module>
from Crypto.PublicKey import _DSA, _slowmath, pubkey
File "/usr/lib64/python2.6/site-packages/Crypto/PublicKey/_DSA.py", line 30, in <module>
from Crypto.PublicKey.pubkey import *
File "/usr/lib64/python2.6/site-packages/Crypto/PublicKey/pubkey.py", line 30, in <module>
from Crypto.Util.number import *
File "/usr/lib64/python2.6/site-packages/Crypto/Util/number.py", line 56, in <module>
if _fastmath is not None and not _fastmath.HAVE_DECL_MPZ_POWM_SEC:
AttributeError: 'module' object has no attribute 'HAVE_DECL_MPZ_POWM_SEC'
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
| 解决方法:
#pip install PyCrypto==2.3
DEPRECATION: Python 2.6 is no longer supported by the Python core team, please upgrade your Python. A future version of pip will drop support for Python 2.6
Collecting PyCrypto==2.3
/usr/lib/python2.6/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:315: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. For more information, see https://urllib3.readthedocs.org/ ... #snimissingwarning.
SNIMissingWarning
/usr/lib/python2.6/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:120: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/ ... ureplatformwarning.
InsecurePlatformWarning
Downloading pycrypto-2.3.tar.gz (331kB)
100% |################################| 331kB 403kB/s
Installing collected packages: PyCrypto
Found existing installation: pycrypto 2.6.1
Uninstalling pycrypto-2.6.1:
Successfully uninstalled pycrypto-2.6.1
Running setup.py install for PyCrypto ... done
Successfully installed PyCrypto-2.3
|
|
|