http://www.perlmonks.org?node_id=415127

state-o-dis-array has asked for the wisdom of the Perl Monks concerning the following question:

Greetings Monks, I am having trouble logging in with the telnet module. Here is my code:
$telnet->open($host); my $mode = $telnet->telnetmode; if ($mode == 0){$telnet->telnetmode(1)} my $fh = $telnet->input_log("tellog.txt"); $telnet->login($username, $passwd);
tellog.txt is revealing that the password is failing, but I have checked and double checked the username and password. I have both the uname and passwd declared in the form my $username='user'; I also tried double quotes, but no change. As you can see I tried forcing telnetmode to On per another post that I found. I can manually telnet to the host all day with the username and password, but for some reason this code is failing. By the way, I have also tried using waitfor to catch the login and password prompts then print to send them, but this doesn't work either. I'm connecting from SunOS 5.6 to SunOS 5.8. Thanks for any wisdom that can be sent my way. Update: Here are the contents of the dump_log
< 0x00000: ff fd 18 ff fd 1f ff fd 23 ff fd 27 ff fd 24 ÿý.ÿý.ÿ +ý#ÿý'ÿý$ > 0x00000: ff fc 18 ff fc 1f ff fc 23 ff fc 27 ff fc 24 ÿü.ÿü.ÿ +ü#ÿü'ÿü$ < 0x00000: ff fe 18 ff fe 1f ff fe 23 ff fe 27 ff fe 24 0d ÿþ.ÿþ.ÿ +þ#ÿþ'ÿþ$. < 0x00010: 0a 0d 0a 53 75 6e 4f 53 20 35 2e 36 0d 0a 0d 00 ...SunO +S 5.6.... < 0x00020: 0d 0a 0d 00 .... < 0x00000: ff fb 01 ff fb 03 ff fd 01 6c 6f 67 69 6e 3a 20 ÿû.ÿû.ÿ +ý.login: > 0x00000: ff fd 01 ff fd 03 ff fc 01 ÿý.ÿý.ÿ +ü. > 0x00000: some hex values here mylogin.. < 0x00000: ff fe 01 some hex values here ÿþ.mylogin.. < 0x00000: 50 61 73 73 77 6f 72 64 3a 20 Passwor +d: > 0x00000: some hex values here mypassword.. < 0x00000: 0d 0a .. < 0x00000: 4c 6f 67 69 6e 20 69 6e 63 6f 72 72 65 63 74 0d Login i +ncorrect. < 0x00010: 0a . < 0x00000: 6c 6f 67 69 6e 3a 20 login:
Other than seeing that the user name and password being sent are indeed correct, this isn't all that meaningful to me, maybe someone can help shed some light?

Replies are listed 'Best First'.
Re: Net::telnet login
by sifen (Beadle) on Dec 15, 2004 at 18:23 UTC

    I don't have any experience with Net::Telnet, but from browsing through the manual I saw a few things that could be of some help. You might want to use the Prompt value of the login() method to specify which prompts to reply to as opposed to using a waitfor, and possibly, when this fails, instead of doing input_log(), you might try dump_log(). The full syntax of login() is:

    $ok = $obj->login(Name => $username, Password => $password, [Prompt => $match,] [Timeout => $secs,]);

    so you also could try setting the timeout longer. It seems to me that this probably doesn't have to do with how you are inputting the password, but rather where the password is being inputted.

      The login and password prompts do appear to be caught correctly, I should have stated so, but the error is not a timeout, but that the user name or password is not correct. The tellog.txt shows that the correct username is input at the login prompt, then it shows the password prompt (wihtout the input which I would think is proper), then it shows another login prompt.
Re: Net::telnet login
by insensate (Hermit) on Dec 15, 2004 at 19:29 UTC
    You say you're going from SunOS 5.6 to SunOS 5.8... the dump log show you're connecting to a SunOS 5.6 box... $host is set to the remote host, not the local host correct?
      I noticed that in the dump log as well... $host is set to a named host - and I just double checked, and I had it set as a literal, no ' around the host name declaration - argh! Good catch, thanks - I finally have a successful log on!
Re: Net::telnet login
by insensate (Hermit) on Dec 15, 2004 at 18:24 UTC
    Are strict and warnings on? My first reaction would be that $passwd may be empty (maybe you declared $password)... other than that, if you're using single quoted declarations... things such as @ or $ in your password shouldn't be an issue. Sorry for stating the obvious.. but I tested this code fine on Win32 to Solaris 8.
      I do have strict on, not warnings, though. My declarations are correct. I'll try warnings and see if that sheds any light. Warnings found a couple of unrelated issues, no change, of to see if dump_log sheds any light.