host.pl 1.18 KB
Newer Older
O'Reilly Media, Inc.'s avatar
O'Reilly Media, Inc. committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
host.pl
#!/usr/local/bin/perl
#
#         host.pl -- a script to build a detailed host file from
#                    information gathered from a router list.
#
#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 (RESULT, ">$workingdir/RESULT") || die "Can't open RESULT file";
while (<RTR>) {
   chomp($rtr="$_");
   @ifIndex=`$snmpwalk $rtr ipAdEntIfIndex`;
   @ipAddress=`$snmpwalk $rtr ipAdEntAddr`;
   $rtr1=`$snmpget $rtr .1.3.6.1.4.1.9.2.1.3.0`;
   chomp(($foo, $RTR) = split (/"/, $rtr1));
   $arraynum=0;
   for $ifnumber (@ifIndex) {
      chomp(($foo, $ifnum) = split(/= /, $ifnumber));
      $ifDescription=`$snmpget $rtr ifName.$ifnum`;
      chomp(($foo, $ipaddr) = split(/: /, $ipAddress[$arraynum]));
      chomp(($foo, $ifdes) = split(/= /, $ifDescription));
      $name="$RTR-$ifdes";
      #$name=~s/\//-/;
      if ( $ifdes eq "Lo0" ) { $name=$RTR };
      print RESULT "$ipaddr\t\t$name\n";
      $arraynum++;
   }
}
close(RTR);
close(RESULT);