我能够对cisco设备进行ssh并且工作正常。我能够运行EXEC模式命令,但我无法执行特权命令。看起来我需要进入启用模式,但我不确定需要在ssh中传递的参数。我的代码如下。你能帮我么?谢谢你的帮助。
import os
import getpass
import paramiko
import xlsxwriter
import socket
import re
import sys
import smtplib
username = 'username'
password = 'password'
print "Running the tests..this might take some time.."
# Opens file in read mode
f1 = open('hostfile','r')
f2 = open('commandfile','r')
# Creates list based on f1
devices = f1.readlines()
commands = f2.readlines()
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
data = []
for device in devices:
column = device.split()
data.append([column[0]])
print column[0]
for command in commands:
try:
conn=ssh.connect(column[0], username=username,
password=password, timeout=4)
if conn is None:
stdin, stdout, stderr = ssh.exec_command(command)
x=stdout.readlines()
print
'*****************************************************************'
print ' Output of ' + command + ' on ' + device
print
'*****************************************************************'
raw_input("Press any key to continue.")
for j in x:
print j
data[-1].append(stdout.read())
ssh.close()
except paramiko.AuthenticationException:
output = "Authentication Failed"
data[-1].append(output)
break
except paramiko.SSHException:
output = "Issues with SSH service"
data[-1].append(output)
break
except socket.error, e:
output = "Connection Error"
data[-1].append(output)
break
data[-1] = tuple(data[-1])
f1.close()
f2.close()
答案 0 :(得分:-1)
一种方法是设置具有更高权限的用户,并且无需进入启用模式。如果AAA设置为在Cisco设备上进行本地身份验证,则在username命令中添加权限15即可。