Guest User

Untitled

a guest
May 22nd, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. import getpass
  2. import sys
  3. import time
  4. import textfsm
  5. import os
  6. from tabulate import tabulate
  7. import re
  8.  
  9.  
  10. from netmiko import ConnectHandler
  11.  
  12. USER = raw_input("Login:")
  13. PASSWORD = getpass.getpass()
  14. FILENAME = raw_input("Name of file with results:")
  15. GETPATH= os.getcwd()
  16. GETPATH2 = (GETPATH+'/IP-ADD.txt')
  17. GETPATH3 = (GETPATH+'/template-desc.template')
  18.  
  19. BOXES_IP = [line.strip() for line in open(GETPATH2, 'r')]
  20. print(BOXES_IP)
  21.  
  22. for IP in BOXES_IP:
  23. print('CONNECTION TO DEVICE {}'.format(IP))
  24. try:
  25. DEVICE_PARAMS = {'device_type': 'juniper_junos',
  26. 'ip': IP,
  27. 'username':USER,
  28. 'password':PASSWORD,
  29. 'verbose': True}
  30. with ConnectHandler(**DEVICE_PARAMS) as sss:
  31. sss.enable()
  32.  
  33. result = sss.send_command('show configuration protocols ospf| match int')
  34. hostname = sss.send_command('show configuration system host-name')
  35. print(result)
  36. except:
  37. print('CONNECTION TO DEVICE FAILS {}'.format(IP))
  38. continue
  39.  
  40. f = open(FILENAME+'.txt', 'a')
  41. for row in hostname:
  42. f.write(row)
  43. for row in result:
  44. f.write(row)
  45. f.close()
  46.  
  47. regex = re.compile(r'^(xe.[0-9].[0-9].[0-9])')
  48. results_list = []
  49.  
  50. b = open(FILENAME+'.txt', 'r')
  51. print b
  52. for line in b:
  53. match = regex.search(line)
  54. if not match: continue
  55. results_list.append(match.group())
  56. print results_list
  57.  
  58. interface xe-1/2/0.0;
  59. interface ge-1/2/1.0;
  60. interface lo0.0 {
Add Comment
Please, Sign In to add comment