我正在尝试减少此列表中打印的端口数:
A.B.C.D 80,280,443,515,631,7627,9100,14000
对我最感兴趣的那些:
A.B.C.D 80,515,9100
为此,我使用这段代码:
foreach (@ips_sorted) {
print "$_\t";
my $hostz = $np->get_host($_);
my $port = 0;
my $output = 0;
$port = $hostz->tcp_ports('open');
if ($port == 80 || $port == 445 || $port == 515 || $port == 9100) {
$output = join ',' ,$port;
}
print $output;
print "\n";
}
Run Code Online (Sandbox Code Playgroud)
我可能不需要说,它不起作用.我明白了:
A.B.C.D 0
Use of uninitialized value $port in numeric eq (==) at parse-nmap-xml.pl line **(line with if).
很可能,表达式$hostz->tcp_ports('open')返回了undef,而不是像你预期的那样.