import json from pyntc import ntc_device as NTC iosvl2 = NTC(host='192.168.1.50', username='******', password='******', device_type='cisco_ios_ssh') iosvl2.open() ios_run = iosvl2.backup_running_config('R100.cfg')
print(json.dumps(router6.facts,indent=2)) print(router6.show('show ip arp')) print(router6.show_list(['show ip inte bri','sho clock','show ip arp'])) print(router6.running_config) router6.config('hostname test-Router6') router6.config_list(['interface loop 111','ip address 111.11.11.11 255.255.255.255','description test loopback','no shut']) print(router6.show('show run | in hostname')) print(router6.show('show run interface loop 111')) router6.save() router6.backup_running_config('Router6.cfg') router6.close()
import json from pyntc import ntc_device as NTC iosvl2 = NTC(host='10.0.0.2', username='******', password='******', device_type='cisco_ios_ssh') iosvl2.open() ios_run = iosvl2.backup_running_config('S1.cfg') iosvl2.close()
import json from pyntc import ntc_device as NTC iosvl2 = NTC(host="192.168.122.82", username="******", password="******", device_type="cisco_ios_ssh") iosvl2.open() ios_run = iosvl2.backup_running_config("iosvl2-1.cfg")
DEVICE = NTC(host=str(IP), username='******', password='******', device_type='cisco_ios_ssh') DEVICE.open() print("Connected to " + str(IP)) # ------------------------------------ print("Facts - " + str(IP)) OUTPUT = DEVICE.facts OUTPUT = json.dumps(OUTPUT, indent=4) print(OUTPUT) # ------------------------------------ print("Running Config - " + str(IP)) OUTPUT = DEVICE.running_config print(OUTPUT) # ------------------------------------ print("Backup of Running Config - " + str(IP)) if not os.path.exists("Configuration Backup"): os.makedirs("Configuration Backup") FILENAME = "Configuration Backup\\device " + str(IP) + ".cfg" DEVICE.backup_running_config(FILENAME) print("Backup Completed for " + str(IP)) # ------------------------------------ DEVICE.close()
with open(IPs) as f: myIPs = f.read().splitlines() for IP in myIPs: print "Establishing Connection to . . " + IP ip = IP ios_device = { "device_type": "cisco_ios", "ip": ip, "username": username, "password": password } ios_device = NTC(host=ip, username=username, password=password,device_type="cisco_ios_ssh") try: ios_device.backup_running_config("Device_IP_"+ ip +".cfg") except (AuthenticationException): print "Authentication failed for: " + ip continue except (NetMikoTimeoutException): print "Time out to device: " + ip continue except (EOFError): print "End of file while attempting device: " + ip continue except (SSHException): print "SSH problem!!! Check SSH on device " + ip
from pyntc import ntc_device as NTC #Define device list device_list = [ '192.168.122.2', '192.168.122.226', ] #Loop for each device for device in device_list: iosvl2 = NTC(host=device, username='******', password='******', device_type='cisco_ios_ssh') print('Accessing device ' + str(device)) #Open SSH session to device and backup config to file iosvl2.open() ios_run = iosvl2.backup_running_config(str(device) + '.cfg') iosvl2.close()
from pyntc import ntc_device as NTC host = '172.31.33.201' iosvl3 = NTC(host=host, username='******', password='******', device_type='cisco_ios_ssh') iosvl3.open() ######################################################## running_config = iosvl3.running_config saveoutput = open('Router' + host, 'w') saveoutput.write(running_config) saveoutput.close ######################################################## # OR ######################################################## running_config = iosvl3.backup_running_config('iosvl3.cfg') ########################################################
from pyntc import ntc_device as NTC SW = NTC(host='192.168.2.11', username='******', password='******', device_type='cisco_ios_ssh') SW.open() SW.backup_running_config('S1_config.cfg') SW.close()
device_type='cisco_ios_ssh') rtr.open() ios_run = rtr.running_config #comment out the below line if you don't want output seen on the screen while running script. print(ios_run) HOST = '192.168.122.26' saveoutput = open('Running-CFG' + HOST, 'w') saveoutput.write(ios_run) saveoutput.close rtr.close() #2nd method-less code, 5 lines of code! #!/usr/bin/env python #!/usr/bin/env python import json from pyntc import ntc_device as NTC rtr = NTC(host='192.168.122.26', username='******', password='******', device_type='cisco_ios_ssh') rtr.open() ios_run = rtr.backup_running_config('switchbackup.cfg')