How to get the hardware inventory of Cisco routers with snmp
How to get the hardware inventory of Cisco routers with snmp
What to do when asked for an updated list of network equipment and there is no inventory system or the list of equipment is outdated. This note seeks to give a little to the solution to these problems. I found a script that can be modified in the convenience based on the requested data.
The script for how to get the hardware inventory, equipment information extracted directly using snmp. This ensures that the information obtained is current, but as shown it is necessary that all computers are configured snmp scanned with the same community string.
Similarly, we also need to net-snmp installed on the computer that runs the script. You may need to modify the path where the executable snmpget, in my case, just type the command without specifying the path, as will also be necessary to modify the work and the community that snmp is used in example works with public, which is not recommended
For this script to work, you must also create an input file containing the names or IP addresses of all devices to be scanned, the script expects to find this file in the same directory.
What to do when asked for an updated list of network equipment and there is no inventory system or the list of equipment is outdated. This note seeks to give a little to the solution to these problems. I found a script that can be modified in the convenience based on the requested data.
#!/bin/sh
#
# inventory.sh – este escript extrae informacion de
# enrutadores, switches (Name, Type, IOS version)
#
#
# Set behaviour
public="public"
workingdir="/home/juan/cisco"
#
LOG=$workingdir/resultado.csv
infile=$workingdir/entrada.txt
snmp="/usr/local/bin/snmpget -v1 -c $public"
#
while read device
do
$snmp $device sysName.0 > /dev/null
if [ "$?" = "0" ] ; then
rtr=`$snmp $device .1.3.6.1.4.1.9.2.1.3.0 | cut -f2 -d\" `
type2=`$snmp $device .1.3.6.1.4.1.9.9.25.1.1.1.2.3 | cut -f2 -d$ `
ios=`$snmp $device .1.3.6.1.4.1.9.9.25.1.1.1.2.5 | cut -f2 -d$ `
prot=`$snmp $device .1.3.6.1.4.1.9.9.25.1.1.1.2.4 | cut -f2 -d$ `
echo "$device, $rtr, $type2, $ios, $prot" >> $LOG
fi
done < $infile
#
# inventory.sh – este escript extrae informacion de
# enrutadores, switches (Name, Type, IOS version)
#
#
# Set behaviour
public="public"
workingdir="/home/juan/cisco"
#
LOG=$workingdir/resultado.csv
infile=$workingdir/entrada.txt
snmp="/usr/local/bin/snmpget -v1 -c $public"
#
while read device
do
$snmp $device sysName.0 > /dev/null
if [ "$?" = "0" ] ; then
rtr=`$snmp $device .1.3.6.1.4.1.9.2.1.3.0 | cut -f2 -d\" `
type2=`$snmp $device .1.3.6.1.4.1.9.9.25.1.1.1.2.3 | cut -f2 -d$ `
ios=`$snmp $device .1.3.6.1.4.1.9.9.25.1.1.1.2.5 | cut -f2 -d$ `
prot=`$snmp $device .1.3.6.1.4.1.9.9.25.1.1.1.2.4 | cut -f2 -d$ `
echo "$device, $rtr, $type2, $ios, $prot" >> $LOG
fi
done < $infile
The script for how to get the hardware inventory, equipment information extracted directly using snmp. This ensures that the information obtained is current, but as shown it is necessary that all computers are configured snmp scanned with the same community string.
Similarly, we also need to net-snmp installed on the computer that runs the script. You may need to modify the path where the executable snmpget, in my case, just type the command without specifying the path, as will also be necessary to modify the work and the community that snmp is used in example works with public, which is not recommended
For this script to work, you must also create an input file containing the names or IP addresses of all devices to be scanned, the script expects to find this file in the same directory.
0 Comments:
Post a Comment