IOS hardware inventory script

Once i was asked to create an excel file of the hardware inventory, one way was to telnet each router execute few commands and manually copy paste the lines to excel file but this was a clerical job so i made a script that collects all this information from the IOS devices.


  • Linux machine with Perl installed
  • apt-get install net-snmp (debian)
  • yum install net-snmp (redhat based)
  • input.txt (a simple IP address list of the devices)
  • set the correct snmp  to variable $snmpro=”your_comm”;
  • result.csv will generate the output file with all the required serial numbers and card details.
  • Put all the files in same directory


perl -v

check if perl installed, if perl is install it will prompt the version of perl install otherwise perl is not installed.

snmpget -v2c -c public IP_Address

provide the correct community and IP address of snmp agent, it should return the host-name of the agent. otherwise you can paste your problem on this blog and ill try my level best to reply ASAP.

open your fav editor and paste the code in the code section.

perl # perl

Some important and Usefull OIDs:

iso. motherboard oid
iso. device
iso. device name serial numbers names hostname


open (RTR, “input.txt”) || die “Can’t open $rtrlist file”;
open (LOG, “>result.csv”) || die “Can’t open $workingdir/RESULT file”;
open (ERR1, “>err.log”) || die “Can’t open $workingdir/RESULT file”;

while (<RTR>) {
  #print $_;
  $snmpget=`snmpget -v2c -c $snmpro $rtr`;
  if ($snmpget =~ /Timeout/) { print ERR1 “cant open $rtrn”; print “can’t open $rtr.n”; } else
  @str = split (/=/,$snmpget);
  @hostname = split (/ /,$str[1]);
  print $hostname[2];

  @snmpname = `snmpwalk -v2c -c $snmpro $rtr`;
  @snmpserial = `snmpwalk -v2c -c $snmpro $rtr`;
  foreach (@snmpname) {
        chomp ($_);
        @name = split (/=/,$_);
        @name1= split (/ /,$name[1]);
        if($name1[2]) {
        @serial1= split (/=/,$snmpserial[$line_num]);
        @serial = split (/ /,$serial1[1]);
        print $name1[2].”=”.$serial[2].”n”;
        print LOG $rtr.”,”.$hostname[2].”,”.$name1[2],$serial[2].”n”;
  #print @snmpname;
  #print @snmpserial;
  #printf LOG (“%-12.12s; %-30.30s; %-25.25s; %-12.12sn”, $RTR, $LOC, $CON, $SIN);
close (RTR);
close (LOG);
close (ERR1);


Related Posts
Comment ( 1 )
  1. Sam Lee
    April 21, 2013 at 11:16 am

    Nice, i use perl script to manage my network too.

Leave a reply