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
|
my ($switch,$ip) = @_;
my $dot1dTpFdbAddress = '.1.3.6.1.2.1.17.4.3.1.1';
my $dot1dTpFdbPort= '.1.3.6.1.2.1.17.4.3.1.2';
my $dot1dBasePortIfIndex= '.1.3.6.1.2.1.17.1.4.1.2';
my $ifName= '.1.3.6.1.2.1.31.1.1.1.1';
$session = new SNMP::Session(DestHost => "$ip", Community => "public", UseSprintValue => 1, Version => 1, UseNumeric => 1);
die "session creation error: $SNMP::Session::ErrorStr" unless (defined $session);
$vars = new SNMP::VarList(["$dot1dTpFdbAddress"], ["$dot1dTpFdbPort"]);
# premiere ligne
my ($macaddr,$portnum) = $session->getnext($vars);
die $session->{ErrorStr} if ($session->{ErrorStr});
#les suivantes
while (!$session->{ErrorStr} and $$vars[0]->tag =~ /^$dot1dTpFdbAddress/){
$ifnum =
(exists $ifnum{$portnum}) ? $ifnum{$portnum} :
($ifnum{$portnum} =
$session->get("$dot1dBasePortIfIndex\.$portnum"));
$portname =
(exists $portname{$ifnum}) ? $portname{$ifnum} :
($portname{$ifnum}=$session->get("$ifName\.$ifnum"));
print "$macaddr sur $portname\n";
($macaddr,$portnum) = $session->getnext($vars);
}; |
Partager