Net::Telnet login() intercept authentication error

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.

born in USSR wrote:

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

thank you

born in USSR wrote:

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.

Rodrigo B. wrote:

born in USSR wrote:

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.

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.