jtzako has asked for the wisdom of the Perl Monks concerning the following question:

I am using Net::Telnet to connect to some devices, however, some devices use "Password:" to request a password and others use "PASSCODE:" for the same. For some reason net::telnet times out on the ones asking for PASSCODE:.

The passcode one looks like this

$ telnet routername Trying <ipaddress>... Connected to routername. Escape character is '^]'. ----------------------- W A R N I N G ------------------------------- bannergoeshere --------------------------------------------------------------------- User Access Verification Username: myusername Enter PASSCODE:

The password one looks like this

$ telnet routername Trying <ipaddress>... Connected to routername. Escape character is '^]'. User Access Verification Username: myusername Password:

Replies are listed 'Best First'.
Re: Net::Telnet - cant detect Passcode prompt?
by hippo (Archbishop) on Apr 05, 2016 at 21:42 UTC
    For some reason net::telnet times out on the ones asking for PASSCODE

    This is precisely the behaviour described in the documentation:

    (the login) method performs a standard login by waiting for a login prompt and responding with $username, then waiting for the password prompt and responding with $password, and then waiting for the command interpreter prompt. If any of those prompts sent by the remote side don't match what's expected, this method will time-out, unless timeout is turned off.

    The correct approach to use is also suggested by the same documentation:

    Use a combination of print() and waitfor() as an alternative to login() or cmd() when they don't do what you want.
      Thanks for that. I somehow missed that it would only accept 'password'. I was able to use this code to get around this:
      $telnet->waitfor('/:/'); $telnet->print($username); $telnet->waitfor('/:/'); $telnet->cmd($password);
Re: Net::Telnet - cant detect Passcode prompt?
by VinsWorldcom (Prior) on Apr 06, 2016 at 01:16 UTC

    By the "User Access Verification" prompt, I'm assuming this is Cisco - so try Net::Telnet::Cisco which has a login() routing routine that handles this for you - either password or passcode.