programming-examples/perl/Network/The gethostbyname function searches for an _etc_hosts entry that matches a specified machine name.pl

15 lines
477 B
Perl
Raw Normal View History

2019-11-15 12:59:38 +01:00
# 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");
}