CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate: Re: [tprizler] Trying to connect using Net::Telnet: Edit Log



tprizler
Novice

Jul 30, 2008, 6:25 AM


Views: 1009
Re: [tprizler] Trying to connect using Net::Telnet


In Reply To
Hi, Found the problem!

Code
   

my $Dump = "/Dump.txt";
my $Input = "/Input.txt";

my $telnet = new Net::Telnet ( Timeout=>10,Port => 2034 ,
Dump_Log => $Dump,
Input_log => $Input,
Prompt => '/login: $/i'); <--------------- This line was unnecessary.
$telnet->open('10.56.49.98');
$telnet->waitfor('/login:.*$/');


Second, i found out that in order to initialize a connection i must use the "Errmode=>""" The thing is that from some reason when I write Errmode=>'die' the connaction fails, and when I write it as "Errmode=>'return'" , the connecion works and I can axecute commands as i wish! Now I have the problem to distinguish between to kinds of prompts: 1. login: 2. [~]# What I worte is :

Code
   
my $telnet = new Net::Telnet ( Timeout=>10,
Port => 2034 ,
Errmode=>'return');
$telnet->open('10.56.49.98');

if ($telnet->waitfor('/login:.*$/')) {
$telnet->waitfor('/login:.*$/');
$telnet->waitfor('/authorized/i');
$telnet->print('root');
$telnet->waitfor('/password: $/i');
$telnet->print('admin');
$telnet->waitfor('/\# $/i');
my @lines = $telnet->cmd('who');
print @lines;
}

elsif ($telnet->waitfor('/\# $/i')) {
my @lines = $telnet->cmd('who');
print @lines;

}


From debugging it a little I dicovered that The If fails.. Is there a right way to do this distinction??? Thanks!!!!


(This post was edited by tprizler on Jul 30, 2008, 6:27 AM)


Edit Log:
Post edited by tprizler (Novice) on Jul 30, 2008, 6:26 AM
Post edited by tprizler (Novice) on Jul 30, 2008, 6:27 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives