Hello there. I have been trying to logon to switches using an array to collect switch IPs and then log onto the switches. I got 2 different ways that I have to use to log on to the switches depending on the configuration of the switches. Some of the switches require a username and password and some only require a password, here is my code for both ways:
#login 1 foreach $host ( @hosts ) { my $conn = Net::Telnet::Cisco::IOS->new( +HOST => $host); # connect to the host $conn->login( Name => $username, Password => $password); $conn->close; }; #Login 2 foreach $host ( @hosts ) { my $conn = Net::Telnet::Cisco::IOS->new( +HOST => $host); # connect to the host $conn->login( Passcode => $passw); $conn->close; };
Both these login ways is tested and works on switches with the different configs. What I want to do is to have both of these in one script so that I can run through the whole range of switches. I was thinking of using an IF statement, but being a noob I dont really know where to start. This is what I was thinking about doing:
foreach $host ( @hosts ) { my $conn = Net::Telnet::Cisco::IOS->new +(HOST => $host); # connect to the host if ( $conn->login( Name => $username, Password => $password)); else( $conn->login( Passcode => $passw));
I know my coding layout is wrong and I am not looking to be spoon fead, but would like someone to point me in the right direction. Thanks
In reply to Net telnet Cisco Login by sout11
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |