# DO NOT USE THIS WITHOUT YOUR NET ADMINS' PERMISSION! # YOU PROBABLY WON'T HURT ANYTHING, BUT YOU'LL UPSET THEM # IF YOU DON'T ASK FIRST. use SNMP; # Requires Net-SNMP package from SourceForge. use strict; my $community; my $defgate; my $mib; my $sess; my $var; my $vb; my %ARP; my %sessparms; # Initialize SNMP. $SNMP::use_sprint_value = 1; # The MIB objects we need are pre-loaded in Net-SNMP. &SNMP::initMib(); $community = 'public'; # Use your read-only community here. $defgate = '127.0.0.1'; # Use your default gateway here. $sessparms{'DestHost'} = $defgate; $sessparms{'Community'} = $community; $sessparms{'Version'} = '2'; # Recommended. $sess = new SNMP::Session(%sessparms); if ( not defined $sess ) { die "Couldn't open SNMP session to $defgate.\n"; } $mib = 'ipNetToMediaPhysAddress'; # ARP table. $vb = new SNMP::Varbind([$mib]); GETARP: while ( $vb->tag eq $mib ) { $var = $sess->getnext($vb); if ( $sess->{ErrorNum} ) { print "Got $sess->{ErrorStr} querying ARP table on $defgate.\n"; last GETARP; } if ( $vb->iid =~ /(\d+\.\d+\.\d+\.\d+)$/ ) { $ARP{$1} = $var; } } # Not the best sort for this, but hey... foreach ( sort keys %ARP ) { print sprintf "MAC for %-15s is %17s.\n", $_, $ARP{$_}; }