# Net::Telnet login() intercept authentication error

**URL:** <https://www.ruby-forum.com/t/net-telnet-login-intercept-authentication-error/175237>\
**Category:** Ruby\
**Created:** [September 10, 2009, 3:45am UTC](https://www.ruby-forum.com/t/net-telnet-login-intercept-authentication-error/175237 "2009-09-10T03:45:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![born\_in\_USSR](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/2bfe46/32.png) [@born\_in\_USSR](https://www.ruby-forum.com/u/born_in_USSR)\
**Post date:** [September 10, 2009, 3:45am UTC](https://www.ruby-forum.com/t/net-telnet-login-intercept-authentication-error/175237/1 "2009-09-10T03:45:59Z")

</div>

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](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.

---

<div class="post-metadata">

**Author:** ![born\_in\_USSR](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/2bfe46/32.png) [@born\_in\_USSR](https://www.ruby-forum.com/u/born_in_USSR)\
**Post date:** [September 10, 2009, 3:49pm UTC](https://www.ruby-forum.com/t/net-telnet-login-intercept-authentication-error/175237/2 "2009-09-10T15:49:14Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![born\_in\_USSR](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/2bfe46/32.png) [@born\_in\_USSR](https://www.ruby-forum.com/u/born_in_USSR)\
**Post date:** [September 11, 2009, 2:18am UTC](https://www.ruby-forum.com/t/net-telnet-login-intercept-authentication-error/175237/3 "2009-09-11T02:18:49Z")

</div>

thank you

---

<div class="post-metadata">

**Author:** ![born\_in\_USSR](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/2bfe46/32.png) [@born\_in\_USSR](https://www.ruby-forum.com/u/born_in_USSR)\
**Post date:** [September 11, 2009, 3:20pm UTC](https://www.ruby-forum.com/t/net-telnet-login-intercept-authentication-error/175237/4 "2009-09-11T15:20:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![born\_in\_USSR](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/2bfe46/32.png) [@born\_in\_USSR](https://www.ruby-forum.com/u/born_in_USSR)\
**Post date:** [September 13, 2009, 10:23pm UTC](https://www.ruby-forum.com/t/net-telnet-login-intercept-authentication-error/175237/5 "2009-09-13T22:23:13Z")

</div>

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.
