Ejemplo n.º 1
0
def try_connect(ipadx):
    try:
        connect_ssh = ConnectHandler(device_type='cisco_ios_telnet',
                                     username=ipadx[1],
                                     password=ipadx[2],
                                     secret=ipadx[3],
                                     ip=ipadx[0])
        connect_ssh.enable()
        find_hostname = connect_ssh.find_prompt()
        connect_ssh.send_command("terminal len 0")
        connect_ssh.open_session_log('results/' + find_hostname + '.txt', 'w')
        connect_ssh.send_command('sh run')  # you can edit this command
        connect_ssh.close_session_log()

    except:
        die.append(ipadx)
        diel.write(ipadx + '\n')
Ejemplo n.º 2
0
        # enter enable mode
        ssh_connection.enable()

        # prepend the command prompt to the result (used to identify the local host)
        result = ssh_connection.find_prompt() + "\n"
        print ("Device name is: "+result)

        # execute the show cdp neighbor detail command
        # we increase the delay_factor for this command, because it take some time if many devices are seen by CDP

        if best_match == 'cisco_ios':
            cmds = commands.commands_ios
        elif best_match == 'cisco_nxos':
            cmds = commands.commands_nxos
        elif best_match == 'cisco_xr':
            cmds = commands.commands_iosxr


    for command in cmds:
        print("Executing: '" + command + "' on " + device)

        result = ssh_connection.send_command(command)

        if onscreen:
            print(result)

        # close SSH connection
    ssh_connection.close_session_log()
    ssh_connection.disconnect()