Generating a Report of Interface Information:
You want to build a spreadsheet of active IP subnets for your network.
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
The netstat.pl script uses SNMP to gather IP subnet information from a list of routers. This ensures that the information is accurate and current. The script gathers all of the pertinent information about each router’s IP interfaces and outputs this information as a CSV file.
The netstat.pl script requires Perl and NET-SNMP and expects to find both in the /usr/local/bin directory. For more information on Perl or NET-SNMP, please see Appendix A. If you keep these programs in a different location, you will need to modify the script appropriately.
Before using the script, you must define two variables, $workingdir and $snmpro. The $workingdir variable must contain the name of directory where you will store the script and its input and output files. The variable, $snmpro must contain the SNMP read-only community string for your routers. The script assumes that the same community string is valid on all devices.
The script systematically queries each router in a list, one after another. It expects to find this list in a file called RTR_LIST, located in the working directory. This router list should contain a single router name or IP address on each line with no comments or other information included. The results of the script will be stored in a file called RESULT.csv, also located in the working directory.
You can then import the RESULT.csv file into a spreadsheet. The results will look similar to the example report shown in Table 2-3.
Table 2-3. An example output of the netstat.pl script
The script captures information about every interface that has been configured with an IP address. This includes interfaces that are administratively or operationally down, loopback interfaces, HSRP addresses, and IP unnumbered interfaces. The script will not display any interfaces or sub interfaces that are not configured for IP.
As a side benefit, this script uses only open standard SNMP MIBs. So you can use it to extract IP interface information from almost any SNMP-enabled device, including nonCisco equipment.