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

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

 



eouti
New User

Apr 13, 2011, 5:57 AM

Post #1 of 1 (2089 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 :

Code
#!/usr/bin/perl 
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();
#Vitesse
my $vitesse = $inter->ifHighSpeed();
#Alias
my $ifalias = $inter->ifAlias();


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

my $oid_cisco_vlans = "1.3.6.1.4.1.9.9.46.1.3.1.1.2.1";
my $vlans = SnmpTable->new($hostname, $oid_cisco_vlans, $community);
$vlans->connexion();
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