2014-06-19 56 views
0

下面我的代碼給出了參考淨::的Telnet EOF讀等待登錄提示:在test.pl線25

#!/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('','[email protected]'); 
$tn->login('$user','$pass'); 
my @out1 = $tn->print("sh run"); 
print "@out1\n"; 

正嘗試通過終端服務器控制檯端口登錄並執行命令,但面對「EOF閱讀等待登錄提示:在test.pl第25行「錯誤。 任何幫助將不勝感激,謝謝。

回答

0

您的問題是第一個->login方法在返回之前等待提示。但是當通過終端服務器(TS)運行telnet時,您將永遠不會在TS上獲得正常提示,它會直接將您傳遞到控制檯端口上的設備。

如果你想留在TS的當前配置,你可能必須聰明使用->waitfor,這是一個有時令人困惑的任務。

我建議你做的是重新配置TS不認證telnet「pass-throughs」,畢竟它是連接到TS的設備,必須使用usrname/password組合來保護。正如您使用Net::Telnet::Cisco我假設TS是思科設備。下面是我們使用我們的(很老)2511個TSES的配置,但這個概念應用到新的思科以及:

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 
! 
0

您正在嘗試登錄兩次:

$tn->login('','[email protected]'); 
$tn->login('$user','$pass'); 

第二次,在登錄提示都已經消失,它會超時等待它。刪除其中的一行。

+0

我刪除1號線也是同樣的錯誤我面臨着同樣的錯誤,我刪除啓用密碼到ma切換,所以現在我可以直接登錄到特權模式的休耕模式SW-SANT-TEST1-T15# – user3740674

+0

不確定你的意思,但你應該只使用'login()',如果設備要求輸入密碼。如果您沒有憑據直接登錄,則可以刪除這兩行。 – AKHolland

+0

好吧我將刪除並嘗試 – user3740674