Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import getpass
- import sys
- import time
- import textfsm
- import os
- from tabulate import tabulate
- import re
- from netmiko import ConnectHandler
- USER = raw_input("Login:")
- PASSWORD = getpass.getpass()
- FILENAME = raw_input("Name of file with results:")
- GETPATH= os.getcwd()
- GETPATH2 = (GETPATH+'/IP-ADD.txt')
- GETPATH3 = (GETPATH+'/template-desc.template')
- BOXES_IP = [line.strip() for line in open(GETPATH2, 'r')]
- print(BOXES_IP)
- for IP in BOXES_IP:
- print('CONNECTION TO DEVICE {}'.format(IP))
- try:
- DEVICE_PARAMS = {'device_type': 'juniper_junos',
- 'ip': IP,
- 'username':USER,
- 'password':PASSWORD,
- 'verbose': True}
- with ConnectHandler(**DEVICE_PARAMS) as sss:
- sss.enable()
- result = sss.send_command('show configuration protocols ospf| match int')
- hostname = sss.send_command('show configuration system host-name')
- print(result)
- except:
- print('CONNECTION TO DEVICE FAILS {}'.format(IP))
- continue
- f = open(FILENAME+'.txt', 'a')
- for row in hostname:
- f.write(row)
- for row in result:
- f.write(row)
- f.close()
- regex = re.compile(r'^(xe.[0-9].[0-9].[0-9])')
- results_list = []
- b = open(FILENAME+'.txt', 'r')
- print b
- for line in b:
- match = regex.search(line)
- if not match: continue
- results_list.append(match.group())
- print results_list
- interface xe-1/2/0.0;
- interface ge-1/2/1.0;
- interface lo0.0 {
Add Comment
Please, Sign In to add comment