#!/usr/bin/perl use strict; use warnings; use IO::Socket::INET; # proxy for client use Getopt::Long; my $toip ='127.0.0.1'; my $toport =1001; my @optdef=("toip=s" => \$toip ,"toport=s" => \$toport ); GetOptions ( @optdef ) or die("Error in command line arguments\n"); my $n=0; while (1) { if (my $toserver=IO::Socket::INET->new(Proto=> "tcp",PeerAddr =>$toip.':'.$toport)) { my $local_port = $toserver->sockport(); print " connect $local_port\n"; while (my $in=<$toserver>){ chomp $in; next unless (length($in)); unless (int(rand(20))) {print "dont reply close\n"; last;} # unless (int(rand(20))) {print "dont reply wait\n"; next;} print $toserver $$,' ',$local_port,' ',$in,' ',$n++,"\n"; } close $toserver; my $sleep=int(rand(20)); print "sleep $sleep\n"; sleep $sleep; } # got }