Telnet question

R

rolfedh

I'll ask the questions first, and then show the code and examples
below:

waitfor is timing the script out. Is it because it isn't recognizing
that password input is complete? or is it because the device doesn't
issue a command prompt after the password is input? (The user has to
hit the Enter key to get the command prompt)?

I've interjected comments on the behavior of the script with <ROLFE-...
below.

I'm running the following script to log on to a peice of hardware:

require 'net/telnet'

tn = Net::Telnet.new('Host' => '192.168.47.150') { |str|
print str }
tn.login("myusername", "mypassword") { |str| print str }

This is how script displays in FreeRIDE:
ruby c:/Documents and Settings/rdlugyhegwer/sampler.rb
Trying 192.168.47.150...
Connected to 192.168.47.150.
WELCOME TO SYMMETRICOM NETWORK INTERFACE!
USER NAME: myusername

<ROLFE-It pauses here for a little while, and then continues with:>

PASSWORD: mypassword
NETWORK INTERFACE 192-8001 (c) 1998 - 2006 SYMMETRICOM
ALL RIGHTS RESERVED
LOGIN SUCCESSFUL!

c:/ruby/lib/ruby/1.8/net/telnet.rb:551:in `waitfor': timed out
while waiting for more data (Timeout::Error)
from c:/ruby/lib/ruby/1.8/net/telnet.rb:678:in `cmd'
from c:/ruby/lib/ruby/1.8/net/telnet.rb:725:in `login'
from c:/Documents and Settings/rdlugyhegwer/sampler.rb:4


If I log in using a terminal program, it looks like this:

WELCOME TO SYMMETRICOM NETWORK INTERFACE!
USER NAME: myusername
PASSWORD: *****
NETWORK INTERFACE 192-8001 (c) 1998 - 2006 SYMMETRICOM
ALL RIGHTS RESERVED
LOGIN SUCCESSFUL!

<ROLFE - the user must hit the ENTER key on this blank line to get the
command prompt>

GOODBYE.

Any suggestions? I've read a lot of the documentation online and tried
variations on the telnet.rb sourcecode. Your help would be very much
appreciated...
 
W

William Ramirez

------=_Part_2245_17266888.1140235775050
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Look at 'expect', it's the standard tool to handle the dialog
interaction.

Net::Telnet has a similiar command: waitfor

It may be that you have to use write and waitfor to accomplish logins on th=
e
system you're using. I was doing some work with some cisco devices a while
back and I had to kludge my way past a few things with those commands.

------=_Part_2245_17266888.1140235775050--
 
R

rolfedh

As a relative newbie, I was frustrated by the lack of good
documentation/comments for RExpect. It seems from other postings to
this list that RExpect doesn't play well with Windows. I decided to use
a different approach explained in a separate reply to this thread.

require 'net/telnet'
require 'time'

t = Time.now
this_time = t.strftime("%y_%m_%d_%H_%M_%S")


tn = Net::Telnet.new( 'Host' => '192.168.47.150',
"Output_log" => "./logs/" + this_time + ".txt")
{ |str| print str }
sleep 1
tn.puts("operator") { |str| print str }
sleep 1
tn.puts('janus') { |str| print str }

#Skip line with no prompt that appears after logging in
tn.puts ''

#Time zone offset
tn.puts("F1")
sleep 1
 
R

rolfedh

After even more tinkering with waitfor and other methods, I ultimately
chose the following BFI approach (which worked!):

require 'net/telnet'
require 'time'

t = Time.now
this_time = t.strftime("%y_%m_%d_%H_%M_%S")


tn = Net::Telnet.new( 'Host' => '192.168.47.150',
"Output_log" => "./logs/" + this_time + ".txt")
{ |str| print str }
sleep 1
tn.puts("operator") { |str| print str }
sleep 1
tn.puts('janus') { |str| print str }

#Skip line with no prompt that appears after logging in
tn.puts ''

#Time zone offset
tn.puts("F1")
sleep 1
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top