title: How to login and access router from remote server using Net::OpenSSH perl package?
body: <p>I want to access router from remote server through Perl script.</p>
  
  <p>My Perl script located on one server to access remote server on that remote server have accessibility of all routers means two tier architecture is there.</p>
  
  <p>I have tried creating remote server tunnel and then access to router with username and password but no luck.  What should I do?</p>
  
  <p><strong>Update:</strong> Following Script</p>
  
  <pre><code>my $ssh = Net::OpenSSH-&gt;new('RemoteHostIp', port =&gt; 3345, user =&gt; 'username', password =&gt; 'password', 'master_opts' =&gt; [-o =&gt; "StrictHostKeyChecking=no"]);
  
  my ($pty, $pid) = $ssh-&gt;open2pty(netcat =&gt; 'router_ip', 23);
  
  my $telnet = Net::Telnet::Cisco-&gt;new(-fhopen =&gt; $pty,
                                       -prompt =&gt; '/.*\$ $/',
                                       -telnetmode =&gt; 0,
                                       -cmd_remove_mode =&gt; 0,
                                       -output_record_separator =&gt; "\r");
  
  $telnet-&gt;waitfor(-match =&gt; '/username\:/', -errmode =&gt; "return") or die "login failed : ".$telnet-&gt;lastline;
  $telnet-&gt;send_wakeup("routerusername");
  
  $telnet-&gt;waitfor(-match =&gt; '/password\:/', -errmode =&gt; "return") or die "login failed : ".$telnet-&gt;lastline;
  $telnet-&gt;send_wakeup("routerpassword");
  
  my @lines = $telnet-&gt;cmd(String =&gt; "sh ver", Timeout =&gt; 10);
  
  print @lines;
  $telnet-&gt;close;
  </code></pre>
  
  <p><strong>Output:</strong> </p>
  
  <p>Use of /g modifier is meaningless in split at /usr/local/share/perl5/Net/Telnet/Cisco.pm line 756.</p>
  
  <p>|-----------------------------------------------------------------|
  | This system is for the use of authorized users only.            |
  | Individuals using this computer system without authority, or in |
  | excess of their authority, are subject to having all of their   |
  | activities on this system monitored and recorded by system      |
  | personnel.                                                      |
  |                                                                 |
  | In the course of monitoring individuals improperly using this   |
  | system, or in the course of system maintenance, the activities  |
  | of authorized users may also be monitored.                      |
  |                                                                 |
  | Anyone using this system expressly consents to such monitoring  |
  | and is advised that if such monitoring reveals possible         |
  | evidence of criminal activity, system personnel may provide the |
  | evidence of such monitoring to law enforcement officials.       |
  |-----------------------------------------------------------------|</p>
  
  <p>write error: filehandle isn't open at test.pl line 45</p>