首先,我是一个初学者。我必须注意到
所以我想比较一个路由器的running-config,我存储在一个本地机器的文本文件中,我想在我的linux终端打印出来的当前running-config..这是我目前得到的.(这是写在VSCODE,所以我可以通过linux终端打开它)
import difflib
import netmiko
routerconnectinfo = { #create variable of information to store
'device_type':'cisco_ios', #connect via ssh
'host':'192.168.56.101', #ip address of the router
'username':'christian', #username of the route
'password':'romero', #password for router
'secret':'chicken'
}
session = netmiko.ConnectHandler(**routerconnectinfo)
session.enable()
config = session.send_command("show running-config")
file = open("running_config_copied.txt", "w")
file.write(config)
file.close()
#HERE I WANT TO DO A COMMAND THAT ISSUES 'SHOW RUNNING-CONFIG' WHICH IS LIVE.. I THEN WANT TO COMPARE THAT
#TO THE TEXT FILE I CREATED AS SHOWN ABOVE
with open('running_config_copied.txt', 'r') as file1:
diffs = difflib.ndiff(file1.readlines(), 'show running-config'())
for diff in diffs:
print(diff)
我试图找出下一部分,这是打印一个'显示运行配置'命令在我的Linux终端,然后将其与我存储的比较。
1条答案
按热度按时间ctehm74n1#
您可以尝试: