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')
continue best_match = guesser.autodetect() print("This device is detected to be model type: " + best_match) if best_match not in ['cisco_ios', 'cisco_nxos', 'cisco_xr']: print("ERROR: " + best_match + " is not currently supported in this revision") continue else: remote_device['device_type'] = best_match ssh_connection = ConnectHandler(**remote_device) ssh_connection.open_session_log("session-log-"+device+".log", mode=u'write') # 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
from netmiko import ConnectHandler from getpass import getpass my_switch = { 'host': '192.168.122.71', 'username': '******', 'password': '******', 'device_type': 'cisco_ios', } net_conn = ConnectHandler(**my_switch) net_conn.open_session_log('{}-2018'.format(my_switch['host'])) filename = 'show_running.0t3B' cmd = 'delete flash0:{}'.format(filename) #output = net_conn.send_command(cmd) output = net_conn.send_command_timing(cmd) if 'Delete filename' in output: output += net_conn.send_command_timing("\n") output += net_conn.send_command_timing("\n") print(output) net_conn.disconnect