diff --git a/perl-xCAT/xCAT/Utils.pm b/perl-xCAT/xCAT/Utils.pm index f49fb3253..f92a9f1c2 100644 --- a/perl-xCAT/xCAT/Utils.pm +++ b/perl-xCAT/xCAT/Utils.pm @@ -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; diff --git a/xCAT-server/lib/xcat/plugins/switchdiscover.pm b/xCAT-server/lib/xcat/plugins/switchdiscover.pm index 344997d2b..ae7a70827 100644 --- a/xCAT-server/lib/xcat/plugins/switchdiscover.pm +++ b/xCAT-server/lib/xcat/plugins/switchdiscover.pm @@ -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++;