Well the following worked fine for me:
#!/usr/bin/perl use Net::Telnet; $telnet = Net::Telnet->new('192.168.1.65'); print "Login Name : "; $HOST = <STDIN>; print "Password : "; $USER = <>; $telnet->login($HOST,$USER) or die print "can't access server"; @ls = $telnet->cmd('ls'); for(@ls){print;}
I do not have the Term::ReadKey module installed on my system so I removed that. There could be your problem. Or at least I had no problem not using this module and that was the only difference between your code and mine. It would also be a good idea to chomp your variables before using them incase a user enters a whitespace at the end of their user or pass or if a newline sneaks through somehow.

Edit:

Ok I installed that module to try and give you some better advice but alas mine runs perfectly.

#!/usr/bin/perl use Net::Telnet; use Term::ReadKey; $telnet = Net::Telnet->new('192.168.1.65'); print "Login Name : "; $HOST = <STDIN>; ReadMode("noecho",STDIN); print "Password : "; $USER = <>; print "\n"; ReadMode("original",STDIN); $telnet->login($HOST,$USER) or die print "can't access server"; @ls = $telnet->cmd('ls'); for(@ls){print;}
Could it be an issue with the telnet server? Does the second user you are trying actually exist on the system?

In reply to Re: login remotely through telnet by Elijah
in thread login remotely through telnet by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.