我的路由器设备有cli mode
和configure mode
,在cli mode
中可以使用edit
命令输入configure mode
。
paramiko不进入配置模式。
import paramiko
import sys
import subprocess
#
# we instantiate a new object referencing paramiko's SSHClient class
#
vm = paramiko.SSHClient()
vm.set_missing_host_key_policy(paramiko.AutoAddPolicy())
vm.connect('13.193.240.45', username='root', password='my_pwd')
#
vmtransport = vm.get_transport()
dest_addr = ('13.57.109.2', 22) #edited#
local_addr = ('13.193.240.45', 22) #edited#
vmchannel = vmtransport.open_channel("direct-tcpip", dest_addr, local_addr)
#
jhost = paramiko.SSHClient()
jhost.set_missing_host_key_policy(paramiko.AutoAddPolicy())
#jhost.load_host_keys('/home/osmanl/.ssh/known_hosts') #disabled#
jhost.connect('13.57.109.2', username='admin', password='pwd', sock=vmchannel)
#
stdin1, stdout1, stderr1 = jhost.exec_command('edit') # there should enter the configure mode.
print(stdout1.read())
print(stderr1.read())
stdin2, stdout2, stderr2 = jhost.exec_command("set interfaces ae16 unit 200 family inet address 1.1.1.14/29") # this command is only can be execute in the configure mode, but in there will report error. there only can execute the `cli mode commands`
#print (stdin2, stdout2.read(), stderr2)
print(stdout2.read())
print(stderr2.read())
stdin, stdout, stderr = jhost.exec_command('commit')
#
#print (stdin, stdout.read(), stderr)
#
jhost.close()
vm.close()
为什么paramiko
无法进入路由器的配置模式?
我的路由器型号为Juniper MX480
。
摘要:
我想执行命令(edit
)进入配置模式,但是似乎paramiko上下文没有执行该操作(没有进入配置模式),因此我无法执行配置模式命令。
我的意思是:
路由器具有cli模式,配置模式,当我执行编辑时应进入配置模式,然后执行configuration mode, but I use paramiko execute the edit
的命令,仍然只能执行cli模式的命令。
EDIT-01
cli模式:
{master}
JD@HK-MX-RE0>
配置模式:
{master}[edit]
jd@HK-MX-RE0#
当我执行edit
或configure private
进入配置模式时:
jd@HK-MX-RE0> configure private
warning: uncommitted changes will be discarded on exit
Entering configuration mode
{master}[edit]
jd@HK-MX-RE0#