文章目录
前置条件
服务器安装python2.7以上,paramiko模块,这两部分安装详见之前文章。 CENTOS6.5 安装PYTHON2.7.16
编写脚本
vi ssh.py
#!/usr/bin/env python
import paramiko
import time
import getpass
import sys
import socket
ip = "10.0.0.3"
username = "radware"
password = "xxxxxxx'"
ssh_client = paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
ssh_client.connect(hostname=ip,port=65422,username=username,password=password)
print "Sucessfully login to ", ip
command = ssh_client.invoke_shell()
command.send("system date\n")
command.send("logout\n")
command.send("y\n")
time.sleep(1)
output = command.recv(65535)
print output
except paramiko.ssh_exception.AuthenticationException:
print "User authentication failed for " + ip + "."
except socket.error:
print ip + " is not reachable."
ssh_client.close
执行结果(正常登陆)
密码错误情况下
原文链接:Python PARAMIKO ssh连接并配置radware,转载请注明来源!