Perl 的 gethostbyaddr 使用方法介绍

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

# The syntax is (name, altnames, addrtype, len, addrs) = 
# gethostbyaddr (inaddr, inaddrtype); 

#!/usr/local/bin/perl 

$machine ="123.1.1.1"; 
@bytes = split (/\./, $machine); 
$packaddr = pack ("C4", @bytes); 
if (!(($name, $altnames, $addrtype, $len, @addrlist) = gethostbyaddr ($packaddr, 2))) { 
    die ("Address $machine not found.\n"); 
} 
print ("Principal name: $name\n"); 
if ($altnames ne "") { 
    print ("Alternative names:\n"); 
    @altlist = split (/\s+/, $altnames); 
    for ($i = 0; $i < @altlist; $i++) { 
        print ("\t$altlist[$i]\n"); 
    } 
}