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

Anyone got a quick script to check which ports are functioning on a range of hosts? I've lost the IP of a router on a class C network, I'd like to try connect to the telnet port of each ip and see which ones accept telnet connections. something like:
$lip = 1; while ($lip >= 254) { $ip = "192.169.128." . $lip; -----ATTEMPT TO CONNECT TO TELNET PORT HERE, PRINT SOMETHING IF SUC +CESSFULL, OTHERWISE, NEXT..... $lip++; }
Easy to think up, another thing to do....

Replies are listed 'Best First'.
Re: Testing ports
by tomhukins (Curate) on Mar 01, 2001 at 19:07 UTC
Re: Testing ports
by rpc (Monk) on Mar 01, 2001 at 22:59 UTC
    Caveat: If you're going to use IO::Socket, you will also need to read the pod for IO::Select to keep connect() from blocking, when you reach a host that is down or has port 23 firewalled.

    I agree to the above post, nmap is a much better solution. Also, nmap logfiles are easily parsable in Perl.