sub check_port { my $host = shift; # hostname or hostname:port my $timeoutseconds = shift || 1; my $proto = "tcp"; my $handle = IO::Socket::INET->new('PeerAddr'=>$host,'Timeout'=>$timeoutseconds, 'Proto'=>$proto); if (defined $handle && $handle) { $handle->close(); return 1; # port in use } return 0; # not reachable or timeout }