使用ssh时exscript存在多个问题:输出延迟、启动连接延迟、授权问题
这是我的密码:使用ssh时exscript存在多个问题:输出延迟、启动连接延迟、授权问题,ssh,paramiko,Ssh,Paramiko,这是我的密码: conn = SSH2() conn.connect(host) conn.authenticate(account) print (conn.response) conn.send('enable 8\n') <--------------first problem: execute("enable 8') does not work here. Can't understand why. I have to use
conn = SSH2()
conn.connect(host)
conn.authenticate(account)
print (conn.response)
conn.send('enable 8\n') <--------------first problem: execute("enable 8') does not work here. Can't understand why. I have to use send
conn.execute('somepassword')
print (conn.response)
conn.execute('term len 0') <--------------fore some reason the output for this command makes it to the outputs list that I am creating below
print (conn.response)
for command in commands:
print "Executing command", command
try:
conn.execute(command)
print (conn.response)
except:
e = sys.exc_info()[0]
output="Unsupported command or timeout"
outputs.append(output)
conn=SSH2()
连接(主机)
连接(帐户)
打印(连接响应)
conn.send('enable 8\n')在会议上讨论了该问题。为了完整起见,我也将在这里回答
第一个问题:
由于某些原因,操作系统猜测者无法正确识别设备,因此使用了通用驱动程序,但该驱动程序不起作用。
这可以通过手动或设置驱动程序(在这种情况下为ios)来解决
第二个问题:
请不要执行密码(execute('somepassword')
)!这很可能会造成混乱。
改用exscripts身份验证/授权机制
以下方面应起作用:
from Exscript.util.interact import read_login
from Exscript.protocols import SSH2
account = read_login()
conn = SSH2()
# setting driver manually would be:
# conn = SSH2(manual_driver="ios")
conn.connect("host")
conn.authenticate(account)
conn.send('enable 8\n')
# if authorization password differs from login password
# you have to set it in account instance
account.set_authorization_password("<enable password>")
conn.app_authorize(account)
conn.autoinit()
outputs = []
for command in commands:
print "Executing command", command
try:
conn.execute(command)
output = conn.response
except:
e = sys.exc_info()[0]
output = "Unsupported command or timeout"
outputs.append(output)
从Exscript.util.interact导入读取登录
从Exscript.protocols导入SSH2
account=read_login()
conn=SSH2()
#手动设置驱动程序将是:
#conn=SSH2(手动驱动程序=“ios”)
conn.connect(“主机”)
连接(帐户)
conn.send('启用8\n')
#如果授权密码与登录密码不同
#您必须在帐户实例中设置它
帐户。设置授权密码(“”)
conn.app\U授权(账户)
conn.autoinit()
输出=[]
对于命令中的命令:
打印“执行命令”,命令
尝试:
conn.execute(命令)
输出=连接响应
除:
e=sys.exc_info()[0]
output=“不支持的命令或超时”
输出。追加(输出)
如果使用exscripts高级API,这可能会更短