我正在尝试使用paramiko通过ssh登录到专家模式。有人可以帮我弄这个吗?执行专家命令后,它应该要求输入密码,并且我应该能够通过我的脚本进行硬编码。
from paramiko import client
from pprint import pprint
class ssh:
client = None
def __init__(self, address, username, password):
print("Connecting to server.")
self.client = client.SSHClient()
self.client.set_missing_host_key_policy(client.AutoAddPolicy())
self.client.connect(address, username=username, password=password, look_for_keys=False)
def sendCommand(self, command):
if(self.client):
stdin, stdout, stderr = self.client.exec_command(command)
while not stdout.channel.exit_status_ready():
# Print data when available
if stdout.channel.recv_ready():
alldata = stdout.channel.recv(1024)
prevdata = b"1"
while prevdata:
prevdata = stdout.channel.recv(1024)
alldata += prevdata
print(str(alldata, "utf8"))
else:
print("Connection not opened.")
connection = ssh("xx.xx.xx.xx", "username", "password")
connection.sendCommand("lock database override")
connection.sendCommand("show hostname")
connection.sendCommand("show version product")
connection.sendCommand("fw vsx stat")
connection.sendCommand("show management interface")
connection.sendCommand("show configuration bonding")
connection.sendCommand("show configuration bridging")
connection.sendCommand("show configuration interface")
connection.sendCommand("show configuration static-route")
connection.sendCommand("show ipv6-state")
connection.sendCommand("show configuration ipv6 static-route")
#After executing the expert command it should ask for password
connection.sendCommand("expert")