cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
3313
Views
0
Helpful
1
Replies

Script to make inventory and that discover the network automatically

Bruna
Level 1
Level 1

Hi Guys,

I'm need of the  script in python to use as inventory, the aims is collect basics information's like sh inventory, sh version, etc of all equipment's in the network using sh cdp detail command to connect automatically and make a parsing of this and finally put in excel spreadsheet. 

Anyone know if already exist this script?

I know about the cicoconfparse and paramiki that makes part of this job but not all.

Thank you in advanced!

1 Reply 1

mgriffith11
Level 1
Level 1

Hi ,

I can give you some assistance in terms of the script not sure what commands you want to run ...This script can connect to a device via SSH,run commands in config mode or enabled mode and also write to a spreadsheet. However packages mentioned in the comments must be installed via pip into a Python 2.7 environment.

##install netmiko package into an python environment using pip to connect to network devices using SSH

##install xlwt package into a python environment using pip for spreadsheet work

from netmiko import ConnectionHandler

from xlwt import Workbook

import logging

ios_Device = {

     'device_type' : 'cisco_ios',

     'ip' : 'enter ip address here',

     'username' : 'enter ssh username here',

     'password' :  'enter ssh password here',

     'secret' : 'enter secret here',

}

commands = ['enter comma separated commands here']

##example

##config_commands = [ 'int fa0/0' , 'ip address dhcp' ]

logging.basicConfig(filename='test.log', level=logging.DEBUG)

logger = logging.getLogger("netmiko")

net_connect = ConnectionHandler(**ios_Device)

##if command doesn't require device to be in configuration mode use this

output = net_connect.send_command(commands)

##if command requires configuration mode then use this

net_connect.enable()

output = net_connect.send_config_set(commands)

##print to console

print(output)

##print to workbook/spreadsheet

wb = Workbook()

sheet1 = wb.add_sheet('Sheet 1')

##write(R,C,Data to write to sheet)

sheet1.write(0,0,output)

##save the spreadsheet

wb.save('savedSpreadSheet.xls')