Net::Telnet login() intercept authentication error

B

born in USSR

CODE:
user_login='user1'
user_paswd='xxxxxx'
...
tserv = Net::Telnet::new("Host" => "192.168.1.5",
"Timeout" => 1, "Prompt" => /[$%#>] \z/n)

begin
ans=tserv.login(user_login,user_paswd)
rescue => err
puts err
end

puts ans
...

if user_login or user_paswd is wrong the application is hanging (don't
know how it is on english, i mean that application stops). How can i
intercept error.

http://www.ruby-doc.org tells that 'The method returns all data received
during the login process from the host, including the echoed username
but not the password (which the host should not echo). If a block is
passed in, this received data is also yielded to the block as it is
received. ', but nothing about wrong authentication.
 
R

Rodrigo Bermejo

born said:
CODE:
user_login='user1'
user_paswd='xxxxxx'
...
tserv = Net::Telnet::new("Host" => "192.168.1.5",
"Timeout" => 1, "Prompt" => /[$%#>] \z/n)

begin
ans=tserv.login(user_login,user_paswd)
rescue => err
puts err
end

puts ans
...

if user_login or user_paswd is wrong the application is hanging (don't
know how it is on english, i mean that application stops). How can i
intercept error.

http://www.ruby-doc.org tells that 'The method returns all data received
during the login process from the host, including the echoed username
but not the password (which the host should not echo). If a block is
passed in, this received data is also yielded to the block as it is
received. ', but nothing about wrong authentication.



Not all exceptions are created the same way

If the exception is a parent of StandardError, you will catch it
with a simple rescue , for other kind of exception this does not apply


begin
tserv = Net::Telnet::new("Host" => "192.168.1.5", "Timeout" => 5,
"Prompt" => /[$%#>] \z/n)
ans=tserv.login(user_login,user_paswd)
rescue TimeoutError => e
ans="Error while connecting: #{e}"
end

puts ans

-ronnie
 
R

Rodrigo Bermejo

born said:
thank you

I just created a thread which may will interest you.
After your questions I stared thinking about ..I was going to warn you
about but did not have the best solution for the problem.


Thread -> Password on code - what's the best way to obfuscate it?


-r.
 
B

born in USSR

Rodrigo said:
I just created a thread which may will interest you.
After your questions I stared thinking about ..I was going to warn you
about but did not have the best solution for the problem.


Thread -> Password on code - what's the best way to obfuscate it?


-r.

Sorry, Rodrigo, but my english is not very good and may be i have not
correctly understood you.
I don't understand why it should be obfuscated.
That part of my program which carries out a role of the telnet-client
was tested by me carefully enough and i have not found out there serious
errors in the authorisation, the code resulted by you works reliably and
stably, by the way once again thanks.
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,962
Messages
2,570,134
Members
46,692
Latest member
JenniferTi

Latest Threads

Top