|
import paramiko
import time
def cisco(ip="10.10.10.5",username="qq",password="huawei",enable="huawei"):
try:
ssh_client = paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh_client.connect(hostname=ip,username=username,password=password)
print ("Successfully connect to", ip)
remote_connection = ssh_client.invoke_shell()
remote_connection.send("enable\n")
remote_connection.send(enable + "\n")
command = open("command.txt", 'r')
remote_connection.send(command.read())
command.seek(0)
time.sleep(60)
log = open(ip+".txt","a")
log.write(remote_connection.recv(100000).decode('ascii'))
except:
error = open("error.txt","a")
error.write(ip+"\n")
cisco()
10.10.10.5这个host是存在,但用户名和密码是错误的,会出发异常处理,但我看了下。只执行了“error = open("error.txt","a")”这条语句,并没有执行“error.write(ip+"\n")” |
|