#!/usr/bin/perl use warnings; use strict; use threads; use IO::Socket::INET qw(); use NET::Ping qw(); use Time::HiRes qw(); my $kHost = '127.0.0.1'; my @ports = (80, 443, 53); for my $port (@ports) { my $SockTest = IO::Socket::INET->new( PeerAddr => $kHost, PeerPort => $port, Proto => 'tcp' ) or next; print "tcp Socket $kHost:$port opened\n"; close ($SockTest); } # pings a plenty for my $mode ('icmp', 'tcp') { my @threads = map { threads->new(sub {doPing($kHost, $_ * 20, $mode)}) } 0 .. 4; for my $thread (@threads) { Time::HiRes::usleep (500_000); $thread->join(); } print "Done $mode test\n"; } print "Done\n"; sub doPing { my ($host, $portBase, $mode) = @_; for my $port ($portBase .. $portBase + 19) { my $ping = Net::Ping->new($mode); $ping->port_number($port); print "$mode ping reply on port $port\n" if $ping->ping($host); } }