Gathering Cisco Router Configurations with Perl
Have a number of routers from which to gather configurations? The following bit of Perl makes this extremely quick and easy, if they all have matching telnet and enable passwords. Must install the CPAN module Net::Telnet::Cisco, and enter the IP addresses of the routers in a file called routerlist.txt, one IP per line. To use this, you just need to replace "TELNET_PASSWORD" and "ENABLE_PASSWORD" below with the appropriate real passwords from the router.
It'll output files in the directory you run it from called IP.add.re.ss.conf, one file per IP.
It'll output files in the directory you run it from called IP.add.re.ss.conf, one file per IP.
#!/usr/bin/perl -wDisclaimer: Are there better ways to write this? I'm sure there are. I don't proclaim to be a programmer, but the way I do things *works*, whether or not it's the "best" way. There's more than one way to do it!
use Net::Telnet::Cisco;
@routers = `cat routerlist.txt`;
foreach my $router (@routers) {
chomp($router);
my $session = Net::Telnet::Cisco->new(Host => $router);
$session->login('','TELNET_PASSWORD');
$session->enable("ENABLE_PASSWORD");
@conf = $session->cmd("wr t");
open LOG, "> $router.conf";
select LOG;
print @conf;
close LOG;
}
4 Comments:
I found that quite interesting becuse it is close to something that's been bothering me for a while.
Do you know how i can use a batch or script, telnet into a Linux box and shut it down?
So the batch/script would:
- telnet 1.2.3.4
- login
- password
- su
- password
- /sbin/shutdown -h now
Much obliged.
Even easier would be to use ssh.
ssh 1.2.3.4 /sbin/shutdown -h now
If you have the ssh keys set properly it will all Just Work.
How can I buy the CD ONLY to the Linksys RE1000 Wireless-N Range Extender?
Thanks for a great article.Netgear Nighthawk App provides a simple and easy interface for Netgear Nighthawk router users. This app allows to setup, control, manage and monitor your home network. If you need any assistance regarding Netgear Nighthawk App Installation or Troubleshooting, Contact support Team at +1-844-456-4180
Post a Comment
<< Home