CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Need a Custom or Prewritten Perl Program?: I need a program that...:
Net::SNMP, get MAC-address and infos by ifname


New User

Apr 13, 2011, 5:57 AM

Post #1 of 1 (2456 views)
Net::SNMP, get MAC-address and infos by ifname Can't Post

Hi, I need to code a perl script to query switchs for my internship. I want to invoke my script with :
- switch ip
- community
- name of the interface (ex. FastEthernet0/9)
And I want him to answer : On this interface Fa0/9 is connected to "MAC of host", with speed : 100, duplex : full...

Here what I've started :

use strict;
use warnings;
use Getopt::Long;
use SnmpTable;
use Net::MAC;
use Net::SNMP;
use Net::SNMP::Interfaces;

my $ifname;
my $hostname;
my $community;
my $version = 1;

GetOptions( "ifname=s" => \$ifname,
"host=s" => \$hostname,
"community=s" => \$community,
"protocol:s" => \$version);

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

#On récupere l'identifiant de l'interface $ifname
my $ifindex = $inter->index();
my $vitesse = $inter->ifHighSpeed();
my $ifalias = $inter->ifAlias();

#Recherche des VLANs
my $numeroportbridge;
my $vlan_trouve;

my $oid_cisco_vlans = "";
my $vlans = SnmpTable->new($hostname, $oid_cisco_vlans, $community);
my %vl = $vlans->requete();
my @tab = keys(%vl);

foreach my $i (@tab) {
if ($i<1000) {
my $comvlan = $community."@".$i;
print $comvlan."\n";
printf "Nom de l'interface : %s --> ifindex = %s, Vitesse = %s, Alias = %s\n", $ifname, $ifindex, $vitesse, $ifalias;

(This post was edited by eouti on Apr 13, 2011, 5:57 AM)


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives