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:
|