#!/usr/bin/env python
import paramiko
import socket
import sys,os
host = sys.argv[1]
user = sys.argv[2]
port = int(sys.argv[3])
auth_method = sys.argv[4]
if auth_method == 'PASSWORD':
password = sys.argv[5]
cmd = sys.argv[6]
else:
cmd = sys.argv[5]
s = paramiko.SSHClient()
s.load_system_host_keys()
s.set_missing_host_key_policy(paramiko.AutoAddPolicy())
#pkey_file = '/home/alex/.ssh/id_rsa'
#key = paramiko.RSAKey.from_private_key_file(pkey_file)
#s.connect(host,port,username,pkey=key,timeout=5)
try:
if auth_method == 'SSH_KEY':
pkey_file = '/home/alex/.ssh/id_rsa'
key = paramiko.RSAKey.from_private_key_file(pkey_file)
s.connect(host,port,user,pkey=key,timeout=5)
elif auth_method == 'PASSWORD':
s.connect(host,port,user,password,timeout=5)
stdin,stdout,stderr = s.exec_command(cmd)
cmd_result = stdout.read(),stderr.read()
print "--------Result from %s -------" % host
for line in cmd_result:
print line,
s.close()
except paramiko.AuthenticationException:
print "\033[31;1m%s Authentication Error!\033[0m" % host
except socket.error:
print "\033[31;1m%s Connection Refused!\033[0m" % host
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341