2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2025-07-28 23:31:13 +00:00

Use arp command to get switch mac address

This commit is contained in:
Casandra Qiu
2016-06-01 17:00:25 -04:00
parent 2794ca51b4
commit 41c1938b8c
2 changed files with 33 additions and 1 deletions

View File

@@ -4711,5 +4711,37 @@ sub get_nmapversion {
return $nmap_version;
}
#--------------------------------------------------------------------------------
=head3 get_macbyarp
Get Mac address by arp -n
Returns:
mac: Mac address
=cut
#--------------------------------------------------------------------------------
sub get_macbyarp {
my $arptable;
my $mac;
my $ip = shift;
if ($ip =~ /xCAT::Utils/)
{
$ip = shift;
}
if ( -x "/usr/sbin/arp") {
$arptable = `/usr/sbin/arp -n`;
}
else{
$arptable = `/sbin/arp -n`;
}
my @arpents = split /\n/,$arptable;
foreach (@arpents) {
if (m/^($ip)\s+\S+\s+(\S+)\s/) {
$mac=$2;
last;
}
}
return $mac;
}
1;

View File

@@ -867,7 +867,7 @@ sub snmp_scan {
my $vendor = get_snmpvendorinfo($request, $ip);
if ($vendor) {
my $mac = get_snmpmac($request, $ip);
my $mac = xCAT::Utils->get_macbyarp($ip);
if (!$mac) {
$mac="nomac_nmap_$counter";
$counter++;