mirror of
https://github.com/xcat2/xcat-core.git
synced 2025-07-29 07:41:31 +00:00
Use arp command to get switch mac address
This commit is contained in:
@@ -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;
|
||||
|
@@ -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++;
|
||||
|
Reference in New Issue
Block a user