diff --git a/xCAT-server/lib/xcat/plugins/switchdiscover.pm b/xCAT-server/lib/xcat/plugins/switchdiscover.pm index 73b331c0b..4c1a417b5 100755 --- a/xCAT-server/lib/xcat/plugins/switchdiscover.pm +++ b/xCAT-server/lib/xcat/plugins/switchdiscover.pm @@ -543,9 +543,9 @@ sub nmap_scan { # If --range options, take iprange, otherwise # use noderange to discover switches. ################################################## - my $ranges = get_ip_ranges($request); + my $ranges = get_ip_ranges($request); - $ccmd = "/usr/bin/nmap -sn -oX - @$ranges"; + $ccmd = "/usr/bin/nmap -sn -oX - @$ranges"; print $ccmd; my $result = xCAT::Utils->runcmd($ccmd, 0); if ($::RUNCMD_RC != 0) @@ -629,8 +629,8 @@ sub snmp_scan { ip : IP address passed by the switch after scan Returns: hose: hostname of the switch - if host is empty, format hostname as switch and ip combination - ex: switch-9-114-5-6 + if host is empty, try to lookup use ip address, otherwise format hostname + as switch and ip combination. ex: switch-9-114-5-6 =cut #-------------------------------------------------------------------------------- sub get_hostname { @@ -638,9 +638,12 @@ sub get_hostname { my $ip = shift; if ( !$host ) { - my $ip_str = $ip; - $ip_str =~ s/\./\-/g; - $host = "switch-$ip_str"; + $host = gethostbyaddr( inet_aton($ip), AF_INET ); + if ( !$host ) { + my $ip_str = $ip; + $ip_str =~ s/\./\-/g; + $host = "switch-$ip_str"; + } } return $host; }