Thursday, December 23, 2021

perl_socket test port

 

#########################################################

# perl_socket.pl                                        #

# run at your own risk ;-) Dik Pater 12-feb-2016        #

#########################################################

print "############################################################################\n";

print "perl_socket:INFO: DONOT RUN IN BACKGROUND ALWAYS TERMINATE AFTER TESTING !! \n";

print "perl_socket:INFO: DONOT RUN IN BACKGROUND ALWAYS TERMINATE AFTER TESTING !! \n";

print "perl_socket:INFO: DONOT RUN IN BACKGROUND ALWAYS TERMINATE AFTER TESTING !! \n";

print "############################################################################\n";

print ;

use IO::Socket;

my ($hostname, $portnumber) = @ARGV;

if (not defined $hostname) {

  die "Need hostname\n";

}

if (defined $portnumber) {

print "############################################################################\n";

print "perl_socket:INFO testing '$hostname' and '$portnumber'\n";

print "perl_socket:INFO goto other system and perform \n";

print "perl_socket:INFO telnet $hostname $portnumber\n";

print "############################################################################\n";

}

 

 my $sock = new IO::Socket::INET (

                                  LocalHost => $hostname,

                                  LocalPort => $portnumber,

                                  Proto => 'tcp',

                                  Listen => 1,

                                  Reuse => 1,

                                 );

 die "Could not create socket: $!\n" unless $sock;

my $new_sock = $sock->accept();

while(<$new_sock>) {

print $_;

}

close($sock);