Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Perl Net::Telnet eof read正在等待登录提示:在test.pl第25行_Perl - Fatal编程技术网

Perl Net::Telnet eof read正在等待登录提示:在test.pl第25行

Perl Net::Telnet eof read正在等待登录提示:在test.pl第25行,perl,Perl,下面给出了我的代码以供参考 #!/usr/bin/perl use strict; use Net::Telnet::Cisco; my ($host, $port, $user, $pass, $command); ##### get host info print 'Enter host: '; chop($host = <STDIN>); ##### get port info print 'Enter port: '; chop($port = <STDIN>)

下面给出了我的代码以供参考

#!/usr/bin/perl
use strict;
use Net::Telnet::Cisco;
my ($host, $port, $user, $pass, $command);

##### get host info
print 'Enter host: ';
chop($host = <STDIN>);
##### get port info
print 'Enter port: ';
chop($port = <STDIN>);
##### get user info
print 'Enter user: ';
chop($user = <STDIN>);
##### get user info & hide input
print 'Enter password: ';
system 'stty -echo';
chop($pass = <STDIN>);
system 'stty echo';
print "\n";

my $tn = new Net::Telnet(Host =>$host, Port =>$port, Timeout => 20)
 or die "connect failed: $!";
$tn->open ($host);
$tn->login('','L@ser123');
$tn->login('$user','$pass');
my @out1 = $tn->print("sh run");
print "@out1\n";
#/usr/bin/perl
严格使用;
使用Net::Telnet::Cisco;
我的($host、$port、$user、$pass、$command);
#####获取主机信息
打印“输入主机:”;
印章($host=);
#####获取端口信息
打印“输入端口:”;
印章(港币=);
#####获取用户信息
打印“输入用户:”;
印章($user=);
#####获取用户信息并隐藏输入
打印“输入密码:”;
系统“stty-echo”;
印章($通行证=);
系统“stty-echo”;
打印“\n”;
my$tn=new Net::Telnet(主机=>$Host,端口=>$Port,超时=>20)
或死“连接失败:$!”;
$tn->open($host);
$tn->登录(“”,'L@ser123');
$tn->login('$user','$pass');
我的@out1=$tn->print(“sh run”);
打印“@out1\n”;
我试图通过终端服务器控制台端口登录并执行命令,但遇到“eof read等待登录提示:在test.pl第25行”错误。
感谢您的帮助。

您尝试登录两次:

$tn->login('','L@ser123');
$tn->login('$user','$pass');

第二次,登录提示将已经消失,等待它将超时。删除其中一行。

您的问题是第一个登录方法在返回之前等待提示。但是,当通过终端服务器(TS)运行telnet时,您永远不会在TS上得到正常提示,它会直接将您传递到控制台端口上的设备

如果您想继续使用TS的当前配置,您可能必须使用
->waitfor
,这是一项有时令人困惑的任务

我建议您做的是重新配置TS,以不对telnet“直通”进行身份验证,毕竟连接到TS的设备必须使用usrname/密码组合进行保护。当您使用
Net::Telnet::Cisco
时,我假设TS是Cisco设备。这是我们(非常旧的)2511 TSE使用的配置,但这一概念也适用于较新的CISCO:

aaa new-model
!
! normal authentication scheme (named 'default') for connections terminating
! ON THE TERMINAL SERVER (here via tacacs+)
aaa authentication login default tacacs+ local
aaa authentication enable default tacacs+ enable
!
! create an authentication scheme (named 'line_auth') with no authentication
aaa authentication login line_auth none

line 1 16
 ! disable access to the TS from the serial line side, i.e only allow
 ! *outgoing* connections
 no exec
 !
 ! use the 'line_auth' authentication scheme, i.e no authentication
 login authentication line_auth
 !
 ! only allow telnet connections to connect to the line
 transport input telnet
!
line vty 0 4
 ! default authentication scheme (this is a default config, so it's
 ! actually not shown in the config).
 login authentication default
!

我删除了第1行,但也出现了相同的错误。我遇到了相同的错误,我删除了ma开关的启用密码,因此现在我可以直接登录到特权模式,如fallows SW-SANT-TEST1-T15#不确定您的意思,但如果设备要求密码,您应该只使用
login()
。如果您在没有凭据的情况下直接登录,您可以删除这两行。@out1=$tn->print(“sh run”)我刚才用cmd代替了print,但在test4diff.pl.save行获取错误模式匹配读取eof