我正在尝试使用Python解析所有可能的路由器命令和子命令
在我当前的代码中:
def getSubcommands(input_cmd):
cmd = ''
print('getSubcommands input cmd = show {} ?'.format(input_cmd))
net_connect.write_channel("show {} ?".format(input_cmd))
time.sleep(0.5)
output = net_connect.read_channel()
output = output.split('\n')
# print(output)
del output[-3:]
del output[0]
res = []
for line in output:
line = line.lstrip()
cmd, description = line.split(' ', 1)
description = description.lstrip().replace('\r', '')
# print(cmd, description)
if cmd == '|' or cmd == '<cr>' or cmd in cmd_dict[input_cmd]:
break
cmd_dict[input_cmd].append(getSubcommands(input_cmd + ' ' + cmd))
return cmd
getSubcommands('aaa locald trace')
输出解析input_cmd
的sub_命令,因此我尝试获得如下输出
output = {'aaa locald trace' : [ sub_command1, ...all other subcommands ], 'aaa locald trace sub_command 1': [ ...all subcommands... ] }
差不多吧
在代码中,它处理获取子命令部分,但我不确定如何递归地存储子命令的所有子命令等等
有什么帮助吗
目前没有回答
相关问题 更多 >
编程相关推荐