wertert has asked for the wisdom of the Perl Monks concerning the following question:
Can someone explaing why this works as $switch is not a filehandle. Now for the big problem. I have to get this running on a windows system running activeperl v5.6.1. Copied it over and everything has stopped working. boo hoo. the line from above has to be swapped to something likeprint $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 inp +ut buffer.
and the whole child/parent thing seems to stop working or deadlock. If I replace-print $switch $byte +$switch->put($byte); ( telnet method )
in the parent section things seem to start going again but obviously nothing it now coming back from the telnet console. What is going on ?? here's the program-while (sysread($switch, $byte2, 1)) -{ - print $client $byte2; -} +sleep(50)
#!/opt/DKBperl/bin/perl $|=1; use IO::Socket; use Net::Telnet; #pass4.pl <switchname> <port> 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 copi +es 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; }
update (broquaint): added a ending </b> tag and put a <readmore> tag before the main section of code
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: telnet passthrough 2
by robartes (Priest) on Nov 12, 2002 at 11:11 UTC | |
|
Re: telnet passthrough 2
by pg (Canon) on Nov 12, 2002 at 17:01 UTC | |
|
Re: telnet passthrough 2
by iburrell (Chaplain) on Nov 12, 2002 at 17:08 UTC |