The gethostbyname function searches for an /etc/hosts entry that matches a specified machine name. : gethostbyname « Network « Perl






The gethostbyname function searches for an /etc/hosts entry that matches a specified machine name.

   

# The syntax is (name, altnames, addrtype, len, addrs) = gethostbyname (inname); 


#!/usr/local/bin/perl 

$machine ="123.1.1.1"; 
if (!(($name, $altnames, $addrtype, $len, @addrlist) = gethostbyname ($machine))) { 
    die ("Machine name $machine not found.\n"); 
} 
print ("Equivalent addresses:\n"); 
for ($i = 0; $i < @addrlist; $i++) { 
    @addrbytes = unpack("C4", $addrlist[$i]); 
    $realaddr = join (".", @addrbytes); 
    print ("\t$realaddr\n"); 
} 

   
    
    
  








Related examples in the same category

1.The gethostbyname function returns an entry from the /etc/hosts file for the name of a specific host passed as an argument.