O'Reilly logo

Cisco IOS Cookbook, 2nd Edition by Ian Brown, Kevin Dooley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required