python - 支持思科路由器,使用 NAPALM,使用 SSH 远程登录

标签 python networking cisco napalm

this image is the diagram for GNS3 of routers want to configure尝试备份 Cisco 路由器的配置。但连接未打开。

    from napalm import *
    import napalm
    drivers = napalm.get_network_driver('ios')
    device_detail = {'hostname':'192.168.1.2','username':'wahid','password':'wahid'}
    router = drivers(**device_detail)
    router.open() 
#The problem is here <- Exception has occurred: ValueError
#Failed to enter enable mode. Please ensure you pass the 'secret' argument to #ConnectHandler.
    print('Connection is Opened with ->{}'.format(device_detail['hostname']))
    config = router.get_config()
    print('Configuratin on this {} router ->'.format(device_detail['hostname']))

最佳答案

你能不能试一下:

from napalm import get_network_driver
from getpass import getpass
 
 
hostname = input("IP address of router: ")
username = input(f"Username of {hostname}: ")
password = getpass(f"Password of {hostname}")
secret = getpass(f"Enable password of {hostname}: ")
 
driver = get_network_driver("ios")
device_detail = {
    "hostname": hostname,
    "username": username,
    "password": password,
    "optional_args": {
        "secret": secret
    }
}
 
with driver(**device_detail) as router:
    print(router.get_facts())

关于python - 支持思科路由器,使用 NAPALM,使用 SSH 远程登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73031189/

相关文章:

python - 如何在 Pelican 中向 im​​g 标签添加属性

perl - 如何使用 2 Foreach Perl 分割字符串

c# - 在 Cisco 电话上获取实时调用信息

python - Paramiko 上的 exec_command 和使用 invoke_shell() 发送有什么区别?

python - 手动实现bayern转RGB

python - 如何从Python脚本获取X字体路径?

c - 如何使用 C 在 Linux 中获取打开的套接字列表?

networking - 如何使用 Hyper-V 连接到网络设置上的 docker 服务器

reactjs - 如何在React Native iOS模拟器上模拟互联网连接?

python - 在 django/python 上访问请求 header