Hi, I made the following changes to getModel, and it now works:
sub getModel {
my $self = shift;
my $cmd = "sh ver";
my $plat;
my @result = $self->cmd( $cmd );
foreach my $line ( @result ) {
if ( $line =~ /^IOS \(tm\) (.+) Software/ ) {
return $1;
} elsif ( $line =~ /cisco (.+) processor/ ) {
return $1;
} elsif ( $line =~ /Cisco (.+) memory\./ ) {
@result = split(/ /,$1);
return $result[0];
}
}
return 0;
}
e.g.
# cat test3.pl
#!/usr/cisco/bin/perl
use lib "/opt/perl5/lib";
use Net::Telnet::Cisco::IOS;
# Connect and login
$connection = Net::Telnet::Cisco::IOS->new( Host => 'aaa.bbb.ccc.ddd');
$connection->login( Name => 'xxxxxxx', Password => 'yyyyyyy' );
# Get the IOS version
if ( $ver = $connection->getIOSVer() ) {
print "The device is running version " . $ver . "\n";
}
else {
print "Can't get the version:\n";
print $connection->errmsg();
}
$model = $connection->getModel();
print "The Model is: ".$model."\n";
# Close the connection
$connection->close();
# ./test3.pl
The device is running version 12.5(0.6.1)PIA1p ENGINEERING WEEKLY BUILD
The Model is: C1861-UC-2BRI-K9