如何在 Perl 中从 telnet 屏幕抓取输出? [英] How can I screen-scrape output from telnet in Perl?

查看:41
本文介绍了如何在 Perl 中从 telnet 屏幕抓取输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在 Perl 中设置 telnet 连接没有问题,并且刚刚发现了 Curses,我想知道我是否可以将两者一起使用来抓取 telnet 会话的输出.

I can setup a telnet connection in Perl no problems, and have just discovered Curses, and am wondering if I can use the two together to scrape the output from the telnet session.

我可以使用下面的简单脚本按行、列查看 STDOUT 的内容:

I can view on a row, column basis the contents of STDOUT using the simple script below:

use Curses;
my $win = new Curses;
$win->addstr(10, 10, 'foo');
$win->refresh;
my $thischar=$win->inch(10,10);
print "Char $thischar\n";

使用下面的命令,我可以打开一个 telnet 连接并毫无问题地发送\接收命令:

And using the below I can open a telnet connection and send \ receive commands with no problem:

use net::telnet;
my $telnet = new Net::Telnet (Timeout => 9999,);
$telnet->open($ipaddress) or die "telnet open failed\n";
$telnet->login($user,$pass);
my $output = $telnet->cmd("command string");

...但我真正想做的是获得 telnet 响应(其中将包括终端控制字符),然后使用 Curses 在行 \ 列的基础上进行搜索.有谁知道我可以将两者连接在一起的方法吗?在我看来,curses 只能对 STDOUT 进行操作

... But what I would really like to do is get the telnet response (which will include terminal control characters) and then search on a row \ column basis using curses. Does anyone know of a way I can connect the two together? It seems to me that curses can only operate on STDOUT

推荐答案

如果您纯粹使用纯文本命令和响应进行交互,您可以使用 Expect 编写脚本,否则,您可以使用 Term::VT102,可让您进行屏幕抓取(读取屏幕的特定部分、发送文本、处理滚动事件、光标移动、屏幕内容更改等)使用 VT102 转义序列进行屏幕控制的应用程序(例如,使用 Curses 库的应用程序).

If you are interacting purely with plain-text commands and responses, you can use Expect to script that, otherwise, you can use Term::VT102, which lets you screen scrape (read specific parts of the screen, send text, handle events on scrolling, cursor movement, screen content changes, and others) applications using VT102 escape sequences for screen control (e.g., an application using the curses library).

这篇关于如何在 Perl 中从 telnet 屏幕抓取输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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