我需要编写脚本来扫描服务器上的端口并生成报告。该脚本应该:用perl检查打开的端口
从文件中读取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但我需要扫描所有打开的端口和列表端口。这个怎么做?
[需要编写perl脚本以扫描服务器上的开放端口并创建报告](http://stackoverflow.com/questions/13724801/need-to-write-a-perl-script-to -scan-open-ports-on-servers-and-create-a-report) –
@sudo_O由于这个问题不是真正的问题,所以这个问题被封闭了。这看起来更好,它有代码要讨论。 – Barmar
正如您在其他问题中提到的那样,为什么不使用'nmap'? – Barmar