use strict; use IO::Socket; my $host = "localhost"; my $sock; print "Open ports:\n"; for(my $port=1; $port < 1024; $port++) { $sock = new IO::Socket::INET(PeerAddr => $host, PeerPort => $port, Proto => 'tcp'); if ($sock) { print "$port\n"; close $sock; } }