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

查看:21
本文介绍了我们如何在 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(或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 :

网络::设备::会话网络::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 mongers 上看到一个帖子,有人提到他们在 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 是一个类似 Linux 的 Windows 环境.它由两部分组成:

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

作为 Linux API 仿真层的 DLL (cygwin1.dll),提供大量 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 核心gnupg制作获取开放式SSHperlperl-ExtUtils获取邮编

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.

如果您习惯使用 Activestate 版本的 perl,您可能习惯使用 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 :

如果您单击 shell 图标,您将打开一个漂亮的 cygwin shell,您可以在其中键入各种命令.您可以将其视为所有意图和目的的 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.

您可能想知道:这是否意味着每次我需要运行我的 perl 脚本时都必须从 cygwin shell 运行它们?".好吧,好消息是,不,你没有..!只要您调用 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:cygwininperl.exe myscript.pl

c: c:cygwininperl.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天全站免登陆