#!/usr/bin/perl -w use strict; use vars qw/@sockets/; use IO::Socket::INET; $| = 1; my $host = $ARGV[0]; my $port = $ARGV[1]; my $timeout = $ARGV[2] or die "Usage: $0 host port timeout\n"; my $count = 0; $SIG{'INT'} = sub { print "\n"; foreach (@sockets) { $_->shutdown(2); close($_) }; exit }; while (1) { my $sock = IO::Socket::INET->new(PeerAddr => $host, PeerPort => $port, Timeout => $timeout, Proto => 'tcp'); if ( $sock ) { push(@sockets,$sock); $count += 1; print "$count "; } else { print "\nmaxed out at $count\n"; last; } } foreach (@sockets) { $_->shutdown(2); close($_); }