我在這裏做錯了什麼,我不知道是什麼。這個小程序應該列出4個IPv4地址,並使用hostent的gethost()來解析域。如果失敗,則保持IPv4格式。失敗與gethost()(使用Net :: hostent)
輸出:
180.76.5.59 has a hostname of 180.76.5.59
199.200.9.44 has a hostname of 199.200.9.44
然後,錯誤我收到:
Can't locate object method "137.48.78.181" via package "Net::hostent" at
./rev.pl line 19 (#1)
(F) You called a method correctly, and it correctly indicated a package
functioning as a class, but that package doesn't define that particular
method, nor does any of its base classes. See perlobj.
Uncaught exception from user code:
Can't locate object method "137.48.78.181" via package "Net::hostent" at ./rev.pl line 19.
at ./rev.pl line 17
17:如果(我的$ H =和getHost($主機))19:$ NAME =($^h - > $名稱());
代碼:
#!/usr/bin/perl
use Modern::Perl;
use Net::hostent;
use diagnostics;
my @ipaddresses = qw/ 180.76.5.59 199.200.9.44 137.48.78.181 137.48.185.207 /;
#host 137.48.78.181
foreach my $host (@ipaddresses)
{
my $name = $host;
# my @sysArg = ("host", $host);
# system(@sysArg);
if (my $h = gethost($host))
{
$name = ($h->$name());
}
print "$host has a hostname of $name\n";
}
你會發現我已經註釋掉系統主機命令,當我使用它工作正常,但我沒有想到的方式來捕捉域(和沉默輸出)。 任何幫助非常感謝。
使用系統時(@sysArg);我得到這個:
Host 59.5.76.180.in-addr.arpa not found: 2(SERVFAIL)
Host 44.9.200.199.in-addr.arpa. not found: 3(NXDOMAIN)
181.78.48.137.in-addr.arpa domain name pointer pc-78-181.hpr.unomaha.edu.
207.185.48.137.in-addr.arpa domain name pointer pki174b-01.ist.unomaha.edu.
Shoulnd''t使用'gethostbyaddr'? – ikegami