dr_beln0ck has asked for the wisdom of the Perl Monks concerning the following question:

this script is supposed to see what ports are open but when it gets to a port thats firewalled it just hangs. Is there a better way to tell a port is open using Socket?
#!/usr/bin/perl -w use IO::Socket; sub sock() { $sock= new IO::Socket::INET ( PeerAddr => $_[0], PeerPort => $_[1], Proto => 'tcp' ); if ($sock){print "port $start_port open\n";} } ($host,$start_port,$end_port) = @ARGV; for(;$start_port<$end_port;$start_port++) { &sock($host,$start_port); }

Replies are listed 'Best First'.
Re: Socket help
by vek (Prior) on Mar 26, 2002 at 19:28 UTC
    Try adding a timeout argument in the constructor.
      nice one it worked.

      cheers :)

        Hope you're wearing a white hat, dr_beln0ck....

        Update: Ah, that's encouraging. :-)

        --
        :wq