Simulate port listen with Perl

Simulate port listen with Perl

On servers behind firewalls were netcat is not available this script can come in handy:


if ($#ARGV != 1 ) {
    print "usage: Use hostname as first argument and port as second argument.\n";


use IO::Socket; 
my $sock = new IO::Socket::INET ( 
                                LocalHost => $ho, 
                                LocalPort => $po, 
                                Proto => 'tcp', 
                                Listen => 1, 
                                Reuse => 1, 
die "Could not create socket: $!\n" unless $sock;
my $new_sock = $sock->accept(); 
while(<$new_sock>) { 
     print $_; 

The above script takes two arguments:

./ localhost 3278

would listen on port 3278 until someone tries to connect.

IO::Socket::INET is usually available on servers where Perl is installed.

The above version is a slightly modified version of a script found here: