December 2006
Intermediate to advanced
1188 pages
72h 8m
English
You need to extract the ARP table from one of your routers to determine the MAC address associated with a particular IP address or the IP address for a particular MAC address.
The script in Example 2-3, arpt.pl, extracts the ARP table for a specified router or IP address and displays the results to standard output. The script expects to find a hostname or IP address of a router on the command line.
Example 2-3. arpt.pl
#!/usr/local/bin/perl
#
# arpt.pl -- a script to extract the ARP cache from a router.
#
#Set behavour
$snmpro="ORARO";
#
$snmpwalk="/usr/local/bin/snmpwalk -v 1 -c $snmpro";
$snmpget="/usr/local/bin/snmpget -v 1 -c $snmpro";
chomp ($rtr=$ARGV[0]);
if ( $rtr eq "" ) {die "$0: Must specify a router \n"};
@iftable=\Q$snmpwalk $rtr ifDescr\Q;
for $ifnum (@iftable) {
chomp (($intno, $intname) = split (/ = /, $ifnum));
$intno=~s/.*ifDescr\.//;
$intname=~s/"//gi;
$arpint{$intno}=$intname;
}
printf ("%-22.22s %-10.10s %-25.25s\n", Address, MAC, Interface);
@atTable=\Q$snmpwalk $rtr .1.3.6.1.2.1.3.1.1.1\Q;
for $atnum (@atTable) {
chomp (($atip, $atint) = split (/ = /, $atnum));
$atip =~ s/.*atIfIndex\.[0-9]+\.1\.//;
$atphys=\Q$snmpget $rtr atPhysAddress.$atint.1.$atip\Q;
chomp(($foo, $phys) = split(/: /, $atphys));
$phys=~s/ /-/gi; chop ($phys);
$phys=~tr/A-Z/a-z/;
$int=$arpint{$atint};
printf ("%-15.15s %17.17s %-25.25s\n", $atip, $phys, $int);
}The arpt.pl script extracts the ARP table from a specific router ...
Read now
Unlock full access