Loading ...
Sorry, an error occurred while loading the content.

Net::SSH::Perl into routers

Expand Messages
  • Dukelow, Don
    I m tryiung to use Net::SSH::Perl to loop through a router list and pull out there rout tables. The routers I have access to there is no problem. But the
    Message 1 of 1 , Apr 28, 2008
    • 0 Attachment
      I'm tryiung to use Net::SSH::Perl to loop through a router list and pull out there rout tables. The routers I have access to there is no problem. But the one's I don't have access to, I'm not able to capture the error and work around it. When I do a "$term = Net::SSH::Perl->new($ip);" on routers that give me connection refused the program just dies with a connection refused message. I don't see any way to capiture the error and work around it.


      use warnings;
      use strict;
      use File::Copy;
      use File::Glob;
      use Net::Ping;
      use Net::Telnet;
      use Net::SSH::Perl;

      &get_router();

      sub get_router {
      my ($router_list, $arp_txt) = @_;

      open IN, $router_list or die "\nCan't open file $router_list $!\n";
      while (<IN>) {
      chomp;
      if (/$matchstr/) {
      &run_TelnetCMD($_, $arp_txt);
      }
      }
      close IN;
      }
      sub run_TelnetCMD {
      my ($str, $arp_txt) = @_;
      print "$str\n";

      my ($foo1, $foo2, $name, $ip, $switchType, $use_login, $logintype) = split /\s+/, $str;
      my ($user, $pass) = split / /, $loginHash{$use_login};
      my $term;

      if (&ping_router($ip)) {
      if ($logintype eq 'ssh') {
      $term = Net::SSH::Perl->new($ip); #This is line giving problem
      my $sttat = $term->login($user, $pass);
      print "STATUS is $sttat\n";
      } elsif ($logintype eq 'telnet') {
      my $prompt = "$name>";
      $term = Net::Telnet->new( Timeout => 10,
      Prompt => "/$prompt/",
      Errmode => 'return',
      # Input_log => 'input',
      # Output_log => 'output',
      Host => "$ip");
      print "TELNET = $term $user $pass\n";
      $term->login($user, $pass);
      my $mesg = $term->errmsg;
      if ((length $mesg) > 1) {
      print "ERROR: $name $mesg\n";
      return;
      }
      } else{
      print "No ligin command $logintype\n";
      return;
      }
      &Telnet_std_router($term, $arp_txt) if ($switchType eq 'cisco');
      $term->cmd('quit');
      return;
      }


      -----
      Don Dukelow
      HP License Team
      Hewlett-Packard Company
      Tel: 810-728-3388
      e-mail: dukelow@...
    Your message has been successfully submitted and would be delivered to recipients shortly.