我们如何在Windows中使用Perl配置SSH? [英] How do we configure SSH using Perl in Windows?

查看:66
本文介绍了我们如何在Windows中使用Perl配置SSH?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以提出一种非常简单的方法来在Windows中使用Net :: SSH :: Perl,而无需所有这些cygwin hacks和所有.

Can anyone suggest a a very simple way to use Net::SSH::Perl in Windows without all those cygwin hacks and all.

每当我尝试安装模块时,它都会带我去其他一些相关的模块,并且过程似乎永无止境.

Whenever I am trying to install the modules it's taking me to some other dependent modules and the process seemed never ending..

预先感谢

推荐答案

这是我发现的相关操作方法的帖子.

Here is a post on how to do it I found.

我最近有一个项目,该项目需要脚本来执行与Cisco设备的SSH会话并进行一些配置更改.我最喜欢的脚本语言当然是perl.

I recently had a project that required a script to perform an SSH session to a Cisco device and make some configuration changes. My favourite scripting language is, of course, perl.

我以前使用Net :: Telnet模块编写脚本,该模块可以Telnet到设备,检测各种设备提示并将命令发送到设备以更改其配置.因此,我认为这将是一个相当简单的案例,即找到一个使用SSH而不是Telnet的合适的类似模块.

I had previously written scripts using the Net::Telnet module that would Telnet to a device, detect various device prompts and send commands to the device to change its configuration. So, I thought that this was going to be a fairly straightforward case of just finding a suitable, similar module that uses SSH instead of Telnet.

我需要提及的另一件事是,由于我目前使用的大多数客户端站点都没有使用Unix(或Windows 2000,2003,XP,Windows 2000,2003,XP),因此我通常只能使用Win32平台. Linux)..在我看来,这确实很可惜,但是我没有设定客户的公司政策.

The other thing that I need to mention is that I am generally constrained to using Win32 platforms (i.e. Windows 200, 2003, XP) due to the fact that most client sites that I work on these days do not use Unix(or Linux) ..which is a real pity in my opinion, but I don't set the corporate policies of my clients.

初步了解了可用的perl模块,发现有许多模块似乎正是我所需要的:

An initial glance of the available perl modules revealed a number of modules which seemed to be just what I needed :

Net :: Appliance :: Session 网络:: SSH :: W32Perl 网络:: SSH

Net::Appliance::Session Net::SSH::W32Perl Net::SSH

因此,我告诉老板,是的,没问题",开始着手整理脚本以通过SSH登录到远程设备,并向其发送一些命令以更改其配置.

So, I told my boss, 'Yep, no problem' and set about pulling together a script to SSH in to a remote device and send it some commands to change its configuration.

经过一天左右的尝试各种模块后,我想:嗯,也许这并没有我想象的那么容易!"

After a day or so of trying various modules, I thought : 'Hmmm, maybe this isn't going to be as easy as I'd thought!'

在Windows环境中使用它时,我看过的每个模块似乎都有一个问题.总结一下,这是我在每个模块中发现的问题:

Each of the modules I'd looked at seemed to have an issue when it came to using it in a Windows environment. To summarise, here are the issues I found with each module :

* Net::Appliance::Session : has a dependency on IO::Pty, which won't ever run on Windows
* Net::SSH::W32Perl : ``getpwuid function is unimplemented'' message`` when building from scratch. Older ppd's found at http://www.soulcage.net/ppds.58 just don't seem to work....even when installed in to the Activestate perl distribution
* Net::SSH : Unix only

因此,在这一点上,我开始认为也许在Windows上根本无法使用....

So, at this point, I was beginning to think that maybe this just wasn't going to work at all on Windows....

然后,我记得在perl贩卖者上发布的帖子,其中有人提到他们曾在cygwin中使用perl来运行Net :: *模块之一.

Then, I remembered seeing a posting on perl mongers where someone has mentioned that they had used perl in cygwin to run one of the Net::* modules.

因此,尽管最初下载并安装cygwin的想法似乎并不吸引人,但我认为我会尝试一下,因为我无处可去.

So, although the thought of having to download and install cygwin didn't initially seem too appealing, I thought I'd give it a go as I had no where else to go.

Cygwin

Cygwin是...嗯,让我直接从cygwin网站上引用:

Cygwin is...well, let me quote directly from the cygwin web site :

``Cygwin是Windows的类似Linux的环境.它由两部分组成:

``Cygwin is a Linux-like environment for Windows. It consists of two parts:

一个DLL(cygwin1.dll),用作提供基本Linux API功能的Linux API仿真层.一组提供Linux外观的工具.

A DLL (cygwin1.dll) which acts as a Linux API emulation layer providing substantial Linux API functionality. A collection of tools which provide Linux look and feel.

Cygwin DLL当前可与所有最新的,商业发行的x86 32位和64位Windows版本一起使用,Windows CE除外.``

The Cygwin DLL currently works with all recent, commercially released x86 32 bit and 64 bit versions of Windows, with the exception of Windows CE.``

因此,它允许您在Linux类型的环境中运行...对于我一直在研究的各种Net :: *模块来说,听起来更有希望.

So, it allows you to run in a Linux-type environment...sounds far more promising for the various Net::* modules that I had been looking at.

此外,一旦安装了基本的cygwin核心,它即可让您下载并安装大量其他产品,包括perl!

Also, once the basic cygwin core is installed, it allows you to download and install a whole host of other goodies, including perl !

因此,我开始通过从cygwin主页下载"setup.exe"文件并在我的PC上运行来安装cygwin.

So, I set about installing cygwin by downloading the 'setup.exe' file from the cygwin home page and running it on my PC.

Cygwin提供了一个错误直观的GUI,可让您选择要从中下载文件的镜像以及要下载的包.

Cygwin provides a failrly intuitive GUI to let you select a mirror to download files from, and which packages you would like to download.

除了为您安装的基本核心cygwin软件包之外,我还安装了这些软件包:

Here are the packages that I installed beyond just the basic core cygwin packages that are installed for you :

gcc-core gnupg 制作 ncftpget 开启SSH 佩尔 perl-ExtUtils get 邮编

gcc-core gnupg make ncftpget openSSH perl perl-ExtUtils wget zip

如果愿意,您还可以安装其他软件,但这对我来说是成功的.

You can install others (in addition) if you like, but these did the job for me.

Perl

一旦我安装了cygwin(包括我包括的perl发行版),就可以添加要使用的模块了(例如Net :: SSH :: Appliance).

Once I had cygwin installed (including the perl distribution that I included), I was all set to add in the modules that I wanted to try to use (e.g. Net::SSH::Appliance).

如果您熟悉Unix系统上的perl,那么您可能会非常熟悉CPAN shell,以便将模块添加到您的perl发行版中.在cygwin下,过程完全相同.

If you are familiar with perl on Unix systems, then you will probably be very familiar with the CPAN shell to add modules into your perl distribution. Under cygwin, the process is exactly the same.

如果您习惯于使用Perl的Activestate版本,则可能习惯于使用Activestate PPM管理器向perl添加新模块.好吧,坏消息是在cygwin下,您没有PPM管理器,并且必须使用CPAN shell,如果您不习惯它,则使用起来会有些棘手.好消息是,您将可以访问更多的perl模块!

If you are used to using the Activestate version of perl, you are probably used to using the Activestate PPM manager to add new modules to perl. Well, the bad news is that under cygwin, you don't have a PPM manager, and you have to use the CPAN shell, which is a little bit trickier to use if you aren't used to it. The good news however, is that you will have access to far more perl modules !

安装cygwin时,它将在屏幕上的某个位置放置一个图标(在您的桌面,快速启动栏或开始菜单上),以便您可以启动cygwin shell(看起来像这样:

When you installed cygwin, it will have put an icon somewhere (either on your desktop, quicklauch bar or start menu) so that you can launch the cygwin shell (it looks something like this :

如果单击外壳图标,将打开一个不错的cygwin外壳,您可以在其中键入各种命令.您可以将其视为所有意图和目的的Unix Shell.

If you click the shell icon, you will get a nice cygwin shell open up where you can type in various commands. You can think of it as a Unix shell to all intents and purposes.

要加载所需的perl模块,需要在命令提示符下输入'cpan'.这将允许您将新模块加载到您的perl发行版中.

To load in the perl modules you'll need, you need to enter 'cpan' at the command prompt. This will allow you to load new modules in to your perl distribution.

现在,当您第一次进入CPAN shell时,它将使您对各种实用程序在何处以及要使用哪个镜像感到困惑.在主要方面,如果您安装了我为cygwin推荐的模块,则可以接受默认值. (您必须自己弄清楚镜子–这取决于您在世界上的哪个位置.)

Now, the first time you go in to the CPAN shell, it will aks you lots of rather awkward questions about where various utilities are and which mirror you would like to use. In the main, if you have installed the modules that I recommended for cygwin, you can accept the defaults. (The mirror you will have to figure out for yourself - it depends where in the world you are).

我建议您更改默认设置的唯一设置是有关是否需要对先决条件模块询问"或遵循"的问题-我会选择跟随"以节省很多麻烦.

The only setting I would recommend you change from the default is the question about whether you should be 'asked or follow' for pre-requisite modules - I would go for 'follow' to save a lot of hassle.

一旦打开了cpan shell(您可以知道,因为现在有了'cpan>'提示),则需要输入以下命令以加载某些需要的perl模块:

Once you have your cpan shell open (you can tell, because you now have a 'cpan>' prompt), you need to enter the following commands to load in some perl modules that you will need :

安装LWP(接受所有默认值来回答任何问题) 安装Net :: Appliance :: Session

install LWP (accept all defaults to any questions asked) install Net::Appliance::Session

输入这些命令后,随着为您安装模块,您会在屏幕上看到很多东西.

When you enter these commands, you will see lots of things flying up the screen as the modules are installed for you.

运行脚本

现在,通过在您的平台上安装cygwin和perl,我们进行了相当大的探索,但是现在您应该可以运行一些perl脚本了.

Well, at this point, we have taken a rather whirlwind tour through getting cygwin and perl instaled on your platform, but you should now be in a position to run some perl scripts.

我们在您的perl发行版中安装了Net :: Appliance :: Session模块,以便我们可以运行perl脚本来使用它向目标设备提供Telnet或SSH会话.

We installed the Net::Appliance::Session module in to your perl distribution, so that we can run perl scripts that will use it to give us either Telnet or SSH sessions to a target device.

由于我们在cygwin环境下运行,因此我们现在可以在Windows平台上使用此模块-仅安装Activestate perl,甚至在Windows下编译我们自己的perl版本都无法实现.因此,现在,我们可以运行perl脚本,使我们能够与仅支持SSH的网络设备执行SSH会话.

As we are running under the cygwin environment, we can now use this module on a Windows platform - something we couldn't do by just installing Activestate perl, or even by compiling our own version of perl under Windows. So, now, we CAN run perl scripts that will allow us to perform SSH sessions to network devices that only support SSH.

您可能想知道:``这是否意味着我每次需要运行cygwin shell时都需要运行perl脚本?''好吧,好消息是,不,你不..!只要您调用cygwin perl可执行文件来运行脚本,它就会在DOS提示符(或系统调度程序!)下正常运行.因此,这可以正常工作:

You may be wondering : ``does that mean that I have to run my perl scripts from the cygwin shell every time I need to run them ?''. Well, the good news is that no, you don't..! As long as you call the cygwin perl executable to run your script, it will run fine from a DOS prompt (or system scheduler !). So, this would work fine :

c:\ c:\ cygwin \ bin \ perl.exe myscript.pl

c:\ c:\cygwin\bin\perl.exe myscript.pl

无论如何,我想这足以让您知道我是如何解决我的特定问题的.我希望在以后的文章中更详细地介绍所有这些内容,并希望提供更多有关如何使用极其有用的Net :: Appliance :: Session模块来创建一些有用的脚本来控制和配置网络设备的信息.

Anyhow, I guess that's enough to let you know how I cracked my particular issue. I hope to cover all of this in a little more detail in future aritcles, as well as providing more informatipon about how to use the incredibly useful Net::Appliance::Session module to create some useful scripts to control and configure your network devices.

http://perlwin32ssh.blogspot.com/2007/07/test_4418.html

这篇关于我们如何在Windows中使用Perl配置SSH?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆