[Python] Python script for Cisco devices

Discussão em 'Python' iniciado por Stack, Dezembro 7, 2024.

  1. Stack

    Stack Membro Participativo

    I want to extract running config from Cisco devices, but not getting desiered output from the code

    import the neccessary modules


    import time, sys, getpass, paramiko

    setup the variables used in the script


    ip = '10.155.111.5'
    username = ""
    password = ""

    establish an SSH session using local authentication to a cisco switch


    remote_conn_pre = paramiko.SSHClient()
    remote_conn_pre.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    remote_conn_pre.connect(ip, username=username, password=password,
    look_for_keys= False, allow_agent=False)
    print "Interactive SSH session established to %s" %ip
    remote_conn = remote_conn_pre.invoke_shell()
    output = remote_conn.recv(1000)
    print output

    check current settings on SNMP


    remote_conn.send("show run | in snmp")

    display the updated port config


    output = remote_conn.recv(3000)
    print "-------------------AFTER-----------------------"
    print '\n'.join(output)

    close out ssh session


    sys.exit("ALL Done!")


    Getting following output


    ====================== RESTART: D:\user\SNMP.py ====================== Interactive SSH session established to 10.155.111.5
    ​

    switch003# -------------------AFTER----------------------- s


    >
    ​

    Continue reading...

Compartilhe esta Página