Perl getnetbyaddr Function



This function returns the information for the network specified by ADDR and type ADDRTYPE in a list context: ($name, $aliases, $addrtype, $net)


Following is the simple syntax for this function −

getnetbyaddr ADDR, ADDRTYPE

Return Value

This function returns undef on error otherwise Network address in scalar context and empty list on error otherwise Network record (name, aliases, address type, network address) in list context.


Following is the example code showing its basic usage −


use Socket;

$iaddr = inet_aton("127.1"); # or whatever address
($name, $aliases, $addrtype, $net)  = getnetbyaddr($iaddr, AF_INET);

print "Name = $name\n";
print "Aliases = $aliases\n";
print "Addrtype = $addrtype\n";
print "Net = $net\n";

When above code is executed, it produces the following result −

Name = default
Aliases = 
Addrtype = 2
Net = 0