#!/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 = ) { 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;