Generating a Report of Interface Information
Problem
You want to build a spreadsheet of active IP subnets for your network.
Solution
Keeping track of assigned IP subnets on a network is a vitally important, but often tedious, task. In large organizations, it can be extremely difficult to maintain accurate and up-to-date addressing information. The Perl script in Example 2-1 uses SNMP to automatically gather current IP subnet information directly from the routers themselves. The script creates an output file in CSV format so you can easily import the information into a spreadsheet.
Example 2-1. netstat.pl
#!/usr/local/bin/perl # # netstat.pl -- a script to build a detailed IP interface # listing directly from a list of routers. # #Set behavour $workingdir="/home/cisco/net"; $snmpro="ORARO"; # $rtrlist="$workingdir/RTR_LIST"; $snmpwalk="/usr/local/bin/snmpwalk -v 1 -c $snmpro"; $snmpget="/usr/local/bin/snmpget -v 1 -c $snmpro"; open (RTR, "$rtrlist") || die "Can't open $rtrlist file"; open (CSV, ">$workingdir/RESULT.csv") || die "Can't open RESULT.csv file"; while (<RTR>) { chomp($rtr="$_"); @ifIndex=\Q$snmpwalk $rtr .1.3.6.1.2.1.4.20.1.2\Q; @ipAddress=\Q$snmpwalk $rtr .1.3.6.1.2.1.4.20.1.1\Q; @ipMask=\Q$snmpwalk $rtr .1.3.6.1.2.1.4.20.1.3\Q; $arraynum=0; print CSV "\n$rtr\n"; print CSV "Interface, IP-Address, Mask, MTU, Speed, Admin, Operational\n"; for $ifnumber (@ifIndex) { chomp(($foo, $ifnum) = split(/= /, $ifnumber)); $ifDescription=\Q$snmpget $rtr ifDescr.$ifnum\Q; $ifMTU=\Q$snmpget ...
Get Cisco IOS Cookbook, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.