for my internship i have to code a network supervisor. I’m writting perl scripts to find all informations (speed, mac address, duplex…) from an interface name on the switch.
There is a function “ifPhysAddress” in this module, but it returns the switch interface mac address, not the mac address of the device connected to it.
How can I find the mac address please ?
Thanks
Here what I’ve started :
#!/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;
You need to follow certain Network Topology algorithms.
For finding connection between a Host machine and a Switch/Router, you have to fist get subnet information from the host machine. Then find out from which switch, the subnet is created. If switch is found with that subnet then the host is connected to that switch.
–> 53
–>10.0.0.1, 192.168.1.1, 8.8.8.1
–>1.3.6.1.2.1.4.21.1.2(ipRouteIfIndex)+10.0.0.1 = 1.3.6.1.2.1.4.21.1.2.10.0.0.1
–> In response of queries in step 3, you will get if index for that IP. Match inIndex from step one. The correnspoding IP will be the IP at that interface. You can get MAC by directly querying that IP.
Thanks.