首页 文章

在perl中使用Telnet时出现问题?

提问于
浏览
1

我在发送命令和从我设置的telnet连接接收文本/数据时遇到了一些麻烦 .

#!perl
 #Telnet.pl

use Net::Telnet;

# Create a new instance of Net::Telnet, 
my $telnetCon = new Net::Telnet (Timeout => 20,
                                Dump_Log   => "dump.log",
                                Input_Log => "infile.log",
                                Output_log => "output.log",
                                Prompt => '/\$ $/') or die "Could not make connection.";

# Connect to the host of the users choice                                
$telnetCon->open('');

#get username and password from user
my $CXusername = '';
my $CXpassword = '';

my $task = '50104'; # Get this input from the search

# Recreate the login
# Wait for the login: message and then enter the username
$telnetCon->waitfor(match => '/login:/i');

# this method adds a \n to the end of the username, it mimics hitting the enter key after entering your username
$telnetCon->print($CXusername);

$telnetCon->waitfor(match => '/Password:/i');

# does the same as the previous command but for the password
$telnetCon->print($CXpassword);

#Wait for the login successful message
$telnetCon->waitfor(match => '/$/');

$telnetCon->cmd("viewtask 50104");
$telnetCon->cmd(" ");
$telnetCon->cmd(" ");

@output = $telnetCon->cmd("who");
print @output;

($output) = $telnetCon->waitfor(match => '/$/');

print "Output: ",$output;

if($searched =~ /MODIFIED files in Task $_[1] :(.*?)The/s){
    # to Logout of the telnet connection
    $telnetCon->print("exit");

    #return the modified data 
    return $1;
}

告诉我,如果问题没有't make sense, I' ll尝试重新编写它 .
First View

Second View

所以这是telnet视图 . 当我输入$ telnetCon-> cmd(“viewtask 50140”)时,我卡在第一张图像上 . 我想进入第二个图像并继续在我的telnet会话中输入命令 .

1 回答

  • 1

    Net::Telnet cmd 方法写入您的命令(附加 \n )并等待提示 . 这与您的程序等待输入完成输出不兼容 .

    我认为在你的情况下你会想要使用 printgetlines 和/或 waitfor 的组合来使这个工作

相关问题