CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced:
How to use telnet via ssh?

 



amyamy
New User

Oct 18, 2004, 8:37 AM

Post #1 of 1 (850 views)
How to use telnet via ssh? Can't Post

hi,
I use ssh first to login a device, then need use telnet to login the other one from the ssh. when I try it, always get the msg:
"fhopen filehandle cannot be opened".
any idea on it? Thanks
#!/usr/bin/perl

use Net::SSH::Perl;


print "Logging in,...\n";


$host = "8.8.8.8.";
print $host;

my $ssh = Net::SSH::Perl->new($host,protocol => 2 );

$ssh->login("usr", "passwd");

$ip2="10.1.1.2"


my($myip,$b,$c) = $ssh->cmd("telnet $ip2");
if ($c != 0) {
#die "cannot telnet\n";
}
else{
print "telnet $ip2";
}


use Net::Telnet;
my $t= new Net::Telnet (
-fhopen => $myip,
-prompt => $prompt,
-telnetmode => 0,
-binmode=>1,
-cmd_remove_mode => 5,
-output_record_separator => "\r");


## Login to remote host.
$t->waitfor(-match => '/password: ?$/i',
-errmode => "return")
or die "problem connecting to host: ", $t->lastline;
$t->waitfor(-match => $t->prompt,
-errmode => "return")
or die "login failed: ", $t->lastline;

## Send command, get and print its output.
@lines = $t->cmd("ls");
print @lines;

}

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives