Net::SSH::Perl 模块
<pre name="code" class="python">Net::SSH::Perl - Perl client Interface to SSH Perl SSH的客户端接口 use Net::SSH::Perl;
my $ssh = Net::SSH::Perl->new($host);
$ssh->login($user, $pass);
my($stdout, $stderr, $exit) = $ssh->cmd($cmd); As of version 1.00, Net::SSH::Perl supports both the SSH1 and
SSH2 protocols natively. The two protocols have different
module prerequisitives, so you need to decide which protocol(s)
you plan to use. If you use one or the other, only those modules
for your chosen protocol will be installed; if you choose both,
all of the supporting modules will be installed. Please choose
the protocols you'd like to use from the following list ("Both"
is the default). [1] SSH1
[2] SSH2
[3] Both SSH1 and SSH2 版本1.00, Net::SSH::Perl 支持SSH1和SSH2协议。 两个协议有不用的模块前提, 因此你需要确定哪些协议 你计划使用。 如果你使用一个或者另一个,只有那些协议你选择的协议会被安装 默认BOTH
Can't locate Net/SSH/Perl.pm in @INC (you may need to install the Net::SSH::Perl module) (@INC contains: /usr/local/perl/lib/site_perl/5.22.1/x86_64-linux /usr/loca-linux /usr/local/perl/lib/5.22.1 .) at a1.pl line 1.
那就是你的perl没找到SSH模块,你可以搜一下你的这个模块撞到哪里了,然后做个连接过去. find / -name SSH 解决:
demo:/root/.cpan/build/Net-SSH-Perl-2.01-czM_pl/blib/lib/Net# cp -R SSH/ /usr/local/perl/lib/site_perl/5.22.1/x86_64-linux/Net/ demo:/root/auto# cat a1.pl
use Net::SSH::Perl;
my $host='192.168.32.79';
my $user='root';
my $passwd='1234567';
my $ssh = Net::SSH::Perl->new($host,port=>22);
$ssh->login($user,$passwd);
my ($stdout,$stderr,$exit) = $ssh->cmd("/sbin/ifconfig -a");
$ssh->cmd("exit");
if($stderr){
print "ErrorCode:$exit\n";
print "ErrorMsg:$stderr";
} else {
print $stdout;
}
exit $exit;
demo:/root/auto# perl a1.pl
eth2 Link encap:Ethernet HWaddr 00:0C:29:93:33:89
inet addr:192.168.32.79 Bcast:192.168.32.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe93:3389/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:90162891 errors:0 dropped:0 overruns:0 frame:0
TX packets:54468730 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:6508620253 (6.0 GiB) TX bytes:4434025169 (4.1 GiB) lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:49500737 errors:0 dropped:0 overruns:0 frame:0
TX packets:49500737 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:48929124401 (45.5 GiB) TX bytes:48929124401 (45.5 GiB) 描述: Net::SSH::Perl是一个all-Perl 模块实现一个SSH客户端, 兼容SSH-1和SSH-2协议。 NET:SSH:Perl 让你简单的和安全的执行命令在远端的机器, 接收输出,错误输出,远端命令的退出状态。 它包含内置的支持各种认证方法(password 认证,RSA 询问响应 认证) 它完全实现了I/O 缓存,packet传输,使用SSH协议的用户认证, 并使用外部的Perl库 来处理所有数据在不安全的网络环境下的发送加密 它也读取存在的SSH配置文件。 使用Net::SSH::Perl 的一个优势封装实现ssh clients 节约了处理的开销:你不需要fork和执行一个单独的进程来连接一个sshd. 根据时间的总量和内存需要来fork一个进程, 这个是相当可观的, 特别是 如果你需要运行在一个持久的Perl环境(mod_perl,比如) 派生一个新的进程是一个消耗内部资源的过程。 它还简化了处理使用基于密码的认证过程,当写一个封装ssh你可能需要使用Expect 来控制ssh客户端,然后给它密码。 Net::SSH::Perl 已经内置支持认证协议,因此不在有任何麻烦在任何外部进程通信的问题 SSH2协议支持(目前Net::SSH::Perl版本是1.00) 是兼容SSH2 在OPENSSH, 也应该完全兼容官方的SSH涉及。 如果你找到一个SSH2 涉及不兼容Net::SSH::Perl, 请让我们知道 如果你正在寻找SFTP支持,看一下Net::SFTP, 提供了功能齐全的SFTP实现, SFTP 需要SSH2协议。 基本的使用: 使用Net:SSH:Perl 是非常简单的: Net::SSH::Perl->new($host, %params) 设置一个新的连接, 调用new方法,连接到$host 和返回一个 Net::SSH::Perl object. new方法接收下面的参数: protocol: 协议你希望使用这个连接: 应该是2,1,'1,2' 或者'2,1' 第一个说,比较简单的, "只有使用协议版本(SSH-2或者SSH-1,分别的) 后面两个指定任何一个协议被使用,但是一个协议(在逗号分隔的列表中的第一个)是优先选择的。 对于这个原因,它是安全的使用后面的2个协议,因为它们确保了任何的方式, 你可以去连接,如果你的服务器不支持列出的第一个协议,第2个会被使用。
(想比你的服务器将至少支持一个协议) 默认值是'1,2' 为了兼容OpenSSH,这意味着客户端会使用SSH-1如果server支持SSH-1, 当然,你也可以使用user/global 配置文件 cipher 指定加密密码的名字 如果你希望使用这个连接,这个鄙视是一个支持的密码, 在SSH-1, 支持的加密的名字是IDEA,DES,DES3,和Blowfish; 在SSH-2,支持的加密是 arcfour, blowfish-cbc, and 3des-cbc. 默认的SSH-1 加密是IDEA, SSH-2 加密是3des-cbc 这个模块,远程执行shell:
demo:/root/auto# cat a1.pl
use Net::SSH::Perl;
my $host='192.168.32.79';
my $user='root';
my $passwd='1234567';
my $cmd='sh /root/auto/a1.sh';
my $ssh = Net::SSH::Perl->new($host,port=>22);
$ssh->login($user,$passwd);
my ($stdout,$stderr,$exit) = $ssh->cmd("$cmd");
$ssh->cmd("exit");
print "\$exit is $exit\n";
if($stderr){
print "ErrorCode:$exit\n";
print "ErrorMsg:$stderr";
} else {
print $stdout;
}
exit $exit; 这个/root/auto/a1.sh 需要在192.168.32.79远端机器上,而不是本地机器上
Net::SSH::Perl 模块的更多相关文章
- perl 简单学习,安装perl模块
检查是否安装了某个perl模块 有多种方式 0.perldoc perlinstall 列出所有的模块及版本号 1. perl -M模块名 -e 1(模块名不加空格) 没有返回值则说明有此模块 2.p ...
- Corrupted MAC on input at /usr/local/perl/lib/site_perl/5.22.1/x86_64-linux/Net/SSH/Perl/Packet.pm l
<pre name="code" class="python">[Thu May 5 11:02:27 2016] [error] Corrupte ...
- Linux CPAN Perl 模块安装
当我们想使用某些Perl模块的时候,很可能会遇到当前系统不存在这个模块的情况,这时我们可以通过使用CPAN来对相应的模块进行获取,下面就介绍一下CPAN的使用方法.首先,我们可以用perl -e 'u ...
- Linux下安装与使用本地的perl模块
转自 http://www.cnblogs.com/xianghang123/archive/2012/08/23/2652806.html Linux下安装与使用本地的perl模块 在使用Linux ...
- linux 查看是否安装perl模块
这里介绍两种linux中查看perl模块是否安装的方法,一种是对于单体的模块,一种是对于群体的. 单体验证: [root@root ~]# perl -MShell -e "print\&q ...
- linux安装perl模块
查询perl CPAN模块 shell>perl -MCPAN -e shell cpan>install module_name 手动安装perl CPAN模块 从 CPAN(h ...
- perl模块安装
转自: http://www.cnblogs.com/itech/archive/2009/08/10/1542832.html http://www.mike.org.cn/blog/index.p ...
- 搭建MHA时 yum 安装perl模块提示 baseurl 错误
今天在搭建MySQL MHA 安装MHA node所需的perl模块(DBD:mysql)时遇到了一个小的错误,如果思路不对的话,还是产生不少麻烦. 现梳理记录下来. 问题现象 执行的命令 yum ...
- Perl模块管理
Perl模块管理 perl有自带的模块,还有第三方模块.自带的模块是随perl安装而安装好的,第三方模块需要从CPAN(Comprehensive Perl Archive Network)上下载并安 ...
随机推荐
- 精简版LVCL,有空看看
http://tothpaul.free.fr/sources.php?lvcl.lvcl1 http://synopse.info/forum/viewtopic.php?id=665
- ORACLE模拟一个数据文件坏块并使用RMAN备份来恢复
1.创建一个实验用的表空间并在此表空间上创建表 create tablespace blocktest datafile '/u01/oradata/bys1/blocktest.dbf' size ...
- php 前台数据显示
<pre name="code" class="html"> public function show(){ echo "访问了index ...
- 使用libcurl进行文件上传
上篇博文讲到了如何使用multicurl来进行http并发访问,今天继续有关curl的主题,来八一八如何使用curl来上传文件,在介绍具体方法之前了解下目前http文件上传的基本实现. rfc1867 ...
- 【opengl】OpenGL中三维物体显示在二维屏幕上显示的变换过程
转自:http://blog.sina.com.cn/s/blog_957b9fdb0100zesv.html 为了说明在三维物体到二维图象之间,需要经过什么样的变换,我们引入了相机(Camera)模 ...
- 用git上传项目到github
1 git clone github仓库地址 2 git add . 3 git commit -m "changes log" 4 git remote add origi ...
- Java设计模式模式观测(Observer Pattern)
Observer Pattern 设计模式通常用于.这是一个事件侦听器模型. 该模型有两个作用,一个是Subject, 有一个Observer.Subject 保存多个Observer参考,一旦一个特 ...
- SQL 语言划分
从功能上划分,SQL 语言能够分为DDL,DML和DCL三大类. 1. DDL(Data Definition Language) 数据定义语言,用于定义和管理 SQL 数据库中的全部对象的语 ...
- js动画学习(二)
四.简单动画之缓冲运动 实现速度的缓冲,即不同位置的速度不同,越靠近目标值速度越小,所以速度值与目标值与当前值之差成正比.这里要注意一个问题就是物体在运动中速度是连续变化的,不是按照整数变化的,当物体 ...
- 使用JQuery插件,排序Gridview的某个字段
1. 前台代码 <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server" ...