Search code examples
perlsnmp

Perl/SNMP : get ifIndex by ifName


i'm new to Perl and SNMP and i'm trying to develop an application to visualise the network for my internship.

I have a first script, given a mac address, a community and a switch's ip, can find the correspondant interfaceSpeed, ifAlias, duplex mode...

$perl mac-ifindex.pl -m 203B697B0438 -h 192.168.1.1 -c public  
Adresse mac : 203B697B0438 => (VLAN : 1, NumPortBridge : 25)  
Ifindex : 10101  
Vitesse : 1000  
Alias : switch-cisco-3750  
Interface name : Gi0/1  
Duplex : 3 (full)  

For my second script, I want to give interface name, community and switch's ip to find all others informations. Which oid to get a table of ifIndex corresponding to port ? or something that could help me.

Thanks, Bye.


Solution

  • I've found a really simple solution :

    use Net::SNMP::Interfaces; 
    my $interfaces = Net::SNMP::Interfaces->new(Hostname => $hostname, Community => $community); 
    my $inter = $interfaces->interface($ifname);
    

    So, I can get ifindex : $inter->index();
    But I need to find mac address too and I don't have the VLAN. Anyone ? Thanks