我需要编写一个脚本来扫描服务器上的端口并生成报告。该脚本应:
从文件中读取 IP 列表;扫描每个 IP,并将结果写入一个文件。
我为此使用以下脚本::
#!/usr/bin/perl -w
use strict;
use IO::Socket::PortState qw(check_ports);
my $hostfile = 'hosts.txt';
my %port_hash = (
tcp => {
22 => {},
443 => {},
80 => {},
53 => {},
30032 => {},
13720 => {},
13782 => {},
}
);
my $timeout = 5;
open HOSTS, '<', $hostfile or die "Cannot open $hostfile:$!\n";
while (my $host = <HOSTS>) {
chomp($host);
my $host_hr = check_ports($host,$timeout,\%port_hash);
print "Host - $host\n";
for my $port (sort {$a <=> $b} keys %{$host_hr->{tcp}}) {
my $yesno = $host_hr->{tcp}{$port}{open} ? "yes" : "no";
print "$port - $yesno\n";
}
print "\n";
}
close HOSTS;
现在我要做的一件事是:
扫描所有打开的端口。
目前它正在扫描端口%port_hash但我需要扫描所有端口并列出打开的端口。这该怎么做?