Retrieve output from HP Switch using Net::SSH2 Perl Module

Viewed 300

enter image description hereI am trying to connect to HP Switch via SSH using Net::SSH2 Perl module (Windows OS). The script is able to connect and authenticate to the device, but the output is not getting retrieved. I am getting blank output.

I have tried with Net::SSH2 shell and exec both, but no luck till now. Also tried with Net::SSH::Any, still no result.

Hp Switch Model : HP 5900 - 7.1.045

Code

use strict;
use Net::SSH2;

my $ssh = Net::SSH2->new();

$ssh->connect('xx.xx.xx.xx');

$ssh->auth(username => 'xxxxx', password => 'xxxxxx');

my  $channel = $ssh->channel() or die 'Error creating channel';

$channel->blocking(0);

$channel->shell();

print $channel "display supervlan\n";       

sleep(5);      

 while(<$channel>)
   {
      print $_;
   }

$channel->close(); 

$ssh->disconnect();

Can somebody please help.

1 Answers

Net::SSH::Any can use any of available backend ssh modules (under windows uses Net::SSH2 if available)

use Net::SSH::Any;

my $ssh = Net::SSH::Any->new(
    "127.0.0.1",
    port => "22",
    user => "xx",
    password => "xx",
    strict_host_key_checking =>0
);
$ssh->error and die $ssh->error;

my ($out, $err) = $ssh->capture2("ls -l /");
print $out;
Related