print $switch $byte # prints one byte to the telnet connection. Confirmed as written by checking DUMP file sysread($switch, $byte2, 1) # reads in one byte from the telnet input buffer. #### -print $switch $byte +$switch->put($byte); ( telnet method ) #### -while (sysread($switch, $byte2, 1)) -{ - print $client $byte2; -} +sleep(50) #### #!/opt/DKBperl/bin/perl $|=1; use IO::Socket; use Net::Telnet; #pass4.pl my($switch)=switchConnect($ARGV[0]); my($server) = IO::Socket::INET->new( Proto => 'tcp', LocalPort => $ARGV[1], Listen => SOMAXCONN, Reuse => 1); die "can't setup server" unless $server; while ($client = $server->accept()) { if (!defined($child_pid = fork())) { die "cannot fork: $!"; } if($child_pid) { print "I'm the parent $child_pid\n"; # REPLY # accept input from the telnet connection (switch) and copies it to heroix (io::socket) while (sysread($switch, $byte2, 1)) { print $client $byte2; } kill("TERM" => $kidpid); # send SIGTERM to child exit 0; } else { print "I'm the child $child_pid\n"; # accept input from heroix (io::socket) and copies it to the telnet connection (switch) $client->autoflush(1); while (sysread($client, $byte, 1)) { $num=ord($byte); if($num==127) {$num=8}; print $switch chr($num); } print "child exiting\n"; } } sub switchConnect { my($switchName)=@_; $t = new Net::Telnet()->new( input_log => "tmp/in", dump_log => "tmp/dump", Timeout => 10, output_log => "tmp/out", errmode => 'return'); print("Attempting to open switch $switchName.."); $t->open(host=>$switchName); if(!$t->waitfor('/login:/')) { print "$hsgname seems engaged- exiting code 10\n"; exit(10); } $t->print("admin"); $t->waitfor('/Password:/'); $t->print("santest1"); if(!$t->waitfor('/\>/')) { print "Timeout on the password. Is the password correct for $hsgname ? - exiting code 11\n"; exit(11); } print "..ok\n"; return $t; }