mirror of
https://github.com/xcat2/xcat-core.git
synced 2025-06-18 12:20:40 +00:00
add hostname lookup by ip for switchdiscover command
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user