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

Hi, I would like to know the prompt when I connect to a cisco box using telnet in order to decide whether I need credentials or not to access the router/switch/whatever.
I've tried with the last_prompt but this gives me nothing before I've actually sent a command to the device.

Any suggestions on how to go about this? Thanks
/JZN

Replies are listed 'Best First'.
Re: Make decisions based on login prompt with Net::Telnet::Cisco
by VinsWorldcom (Prior) on Apr 29, 2011 at 13:11 UTC

    Using the perldoc of Net::Telnet (which N::T::C uses for the heavy lifting), we see:

    last_prompt - last prompt read
    $string = $obj->last_prompt;
    $prev = $obj->last_prompt($string);

    With no argument this method returns the last prompt read by cmd() or login().

    So you need to 'try' to login to determine which login (user/pass or just pass) you'll need.

    VinsWorldcom@\\vmware-host\Shared Folders> cat test.pl #!/usr/bin/perl use strict; use warnings; use Net::Telnet::Cisco 1.10; my $session = Net::Telnet::Cisco->new( Host => $ARGV[0], binmode => 1, Errmode => 'return', ) or die "Failed to connect"; $session->login; printf "%s\n", $session->last_prompt; # if/then logic based on "$session->last_prompt" goes here $session->close;

    And now the output - first to a router needing User/Pass, second to a router just requiring a password:

    VinsWorldcom@\\vmware-host\Shared Folders> test.pl r1 Username: VinsWorldcom@\\vmware-host\Shared Folders> test.pl r2 Password: