#!/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); } } #### tcp Socket 127.0.0.1:80 opened tcp Socket 127.0.0.1:443 opened icmp ping reply on port 0 icmp ping reply on port 20 icmp ping reply on port 21 icmp ping reply on port 1 icmp ping reply on port 2 icmp ping reply on port 22 icmp ping reply on port 23 ... icmp ping reply on port 96 icmp ping reply on port 97 icmp ping reply on port 98 icmp ping reply on port 99 Done icmp test tcp ping reply on port 80 Done tcp test Done