Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Fastest way to determine whether a specific port is open via a Socket

by tcf03 (Deacon)
on Oct 30, 2006 at 20:30 UTC ( [id://581373] : note . print w/replies, xml ) Need Help??


in reply to Fastest way to determine whether a specific port is open via a Socket

The following should work for you
use strict; use warnings; use IO::Socket::INET; sub connected { my $host = shift; my $tcp_port = shift; my $sock = IO::Socket::INET ->new( Timeout => 2, PeerAddr => $host, PeerPort => $tcp_port, Proto => 'tcp' ); return $sock ? 0 : 1; }
Ted
--
"That which we persist in doing becomes easier, not that the task itself has become easier, but that our ability to perform it has improved."
  --Ralph Waldo Emerson
  • Comment on Re: Fastest way to determine whether a specific port is open via a Socket
  • Download Code