perl登录ssh

use warnings;
use strict;
use Net::SSH::Perl;

my $host = '192.168.255.128';
my $username = 'root';
my $password = 'root';

my $ssh = Net::SSH::Perl->new($host,port=>22);
$ssh->login($username, $password);
my ($stdout, $stderr, $exit) = $ssh->cmd('ifconfig');
if($stderr){
    print "Error:$stderr\n";
}else{
    print $stdout;
}
exit $exit;

挺好用的, 用法没有太复杂

posted on 2017-02-22 05:29  Perl6  阅读(1203)  评论(0编辑  收藏  举报

导航