简体   繁体   English

在perl中使用Telnet是否有问题?

[英]Trouble using Telnet in perl?

I'm having some trouble send commands and receiving text/data from the telnet connection that I set up. 我在发送命令以及从我设置的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;
}

Tell me if the question doesn't make sense, I'll try and reword it. 告诉我这个问题是否有道理,我将尝试改写。 初见第二种观点

So this is the telnet view. 这就是telnet视图。 I get stuck on the first image when i enter the $telnetCon->cmd("viewtask 50140"). 输入$ telnetCon-> cmd(“ viewtask 50140”)时,我卡在第一张图像上。 I want to get to the second image and continue entering commands into my telnet session. 我想转到第二个图像,然后继续在telnet会话中输入命令。

The Net::Telnet cmd method writes your command (with a \\n appended) and waits for the prompt. Net::Telnet cmd方法写入您的命令(附加\\n )并等待提示。 this is incompatible with your program's waiting for input to complete output. 这与程序的等待输入完成输出不兼容。

I think in your case you would want to use a combination of print and getlines and/or waitfor to get this to work 我觉得你的情况,你可能需要使用的组合printgetlines和/或waitfor来得到这个工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM