Perl脚本无法打开调制解调器上的端口号失败

时间:2016-02-25 08:35:30

标签: perl telnet

我有一个perl脚本telnet到特定的IP和端口号。但是,如果我在建立连接后打印结果,则端口号为23(默认值)。因此,调制解调器不鼓励从脚本触发的命令。

以下是我的脚本。请指教。

脚本:

#!/usr/bin/perl -w
use lib ("/u/dclement/lib/perl");
use Net::Telnet ();

$HOSTNAME = "192.168.xx.xx";
$HOSTPORT = "9998";

$conn = new Net::Telnet (Timeout => "1");

$conn->binmode(1);              # don't translate CRLF
$conn->errmode("return");       # enable error trapping
$conn->telnetmode(0);           # turn off telnet mode
$conn->dump_log("LOGFILE");     # output log file filehandle
$conn->output_record_separator("");

print "CONNECTING TO $HOSTNAME and $HOSTPORT\n";
# open connection to host $HOSTNAME and port $HOSTPORT
# and die if there is a problem
unless ($conn->open(Host => $HOSTNAME, Port => $HOSTPORT))
{
    die "Error opening socket:: ".$conn->errmsg();
}
print "CONNECTED TO ".$conn->host().", PORT ".$conn->port()."\n";

输出

CONNECTING TO 192.168.xx.xx and 9998
CONNECTED TO 192.168.xx.xx, PORT 23

1 个答案:

答案 0 :(得分:0)

您可以尝试下面的代码并查看是否有任何连接问题9998端口:

$telnetOutput = telnet 192.168.xx.xx 9998 ; print "\n telnet command output1: $telnetOutput \n"; $telnetOutput = telnet 192.168.xx.xx 23 ; print "\n telnet command output2: $telnetOutput \n";