Advertisement
Guest User

Untitled

a guest
Feb 26th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. import textfsm
  2. from pprint import pprint
  3. import netmiko
  4. from getpass import getpass
  5.  
  6. ip = input("Insert IP: ")
  7. username = input("Insert username: ")
  8. password = getpass("Insert password: ")
  9.  
  10. cisco_vios = {
  11. 'device_type': 'cisco_ios',
  12. 'ip': ip,
  13. 'username': username,
  14. 'password': password,
  15. }
  16.  
  17.  
  18. net_connect = netmiko.ConnectHandler(**cisco_vios)
  19.  
  20. string_interface = net_connect.send_command('show interface')
  21.  
  22. template_file = open("showinterface.template")
  23. template = textfsm.TextFSM(template_file)
  24. result_template = template.ParseText(string_interface)
  25.  
  26. interface_list = list()
  27. for list in result_template:
  28. resultDict = dict()
  29. resultDict["interface"] = list[0]
  30. resultDict["mac address"] = list[1]
  31. resultDict["ip address"] = list[2]
  32. resultDict["MTU"] = list[3]
  33. resultDict["bandwith"] = list[4]
  34.  
  35. interface_list.append(resultDict)
  36. pprint(interface_list)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement