Need a perl script

iyer

Junior Member
May 25, 2005
1
0
0
Hi,
I need to run a set of cisco commands on switches and routers to get certain info.
I am thinking of automating this process by running a perl script.
Can anyone help me on this.
I am looking for some sample scripts.

Thanks
iyer.
 

einstein1

Junior Member
May 26, 2005
5
0
0
Originally posted by: iyer
Hi,
I need to run a set of cisco commands on switches and routers to get certain info.
I am thinking of automating this process by running a perl script.
Can anyone help me on this.
I am looking for some sample scripts.

Thanks
iyer.

 

nweaver

Diamond Member
Jan 21, 2001
6,813
1
0
use the net::telnet module...I have automated some test lab setups by using perl scripts with this module as CGI scripts.

 

ScottMac

Moderator<br>Networking<br>Elite member
Mar 19, 2001
5,471
2
0
Dionic: Thanks!

mweaver: Have you used net:telnet:cisco ? I've got it but haven't had time to mess with it.

Just curious ...


Scott
 

nweaver

Diamond Member
Jan 21, 2001
6,813
1
0
Here is a script I use....


#!/usr/bin/perl
#AP must be at default config
use warnings;
use strict;
use Net::Telnet;
#Declare all global variables
my $t1;
my $t2;
my $t3;
my $ap1 = "192.168.200.52";
my $ap2 = "192.168.200.53";
my $ap3 = "192.168.200.56";
my $lab;
my $ssidap1g = "ccx2g";
my $ssidap1a = "ccx2a";
my $ssidap2g = "ccx2g1";
my $ssidap2a = "ccx2a1";
my $ssidap3g = "ccx2g2";
my $ssidap3a = "ccx2a2";
my $un = "cisco";
my $pw = "Cisco";
#Setup new telnet, and login/go to global configuration mode
$t1 = new Net::Telnet ();
$t1->open($ap1);
$t1->waitfor('/Username/');
$t1->print("$un");
$t1->waitfor('/Password:/');
$t1->print("$pw");
$t1->print("enable");
$t1->waitfor('/Password:/');
$t1->print("$pw");
$t1->waitfor('/#/');
$t1->print("Conf term");
$t1->waitfor('/config/');
#Script specific stuff here
#AP 1 Config
$t1->print("int dot11 0");
$t1->waitfor('/config/');
$t1->print("no ssid tsunami");
$t1->waitfor('/config/');
$t1->print("ssid $ssidap1g");
$t1->waitfor('/config/');
$t1->print("authentication open");
$t1->waitfor('/config/');
$t1->print("guest-mode");
$t1->waitfor('/config/');
$t1->print("!");
$t1->waitfor('/config/');
$t1->print("!");
$t1->waitfor('/config/');
$t1->print("int dot11 1");
$t1->waitfor('/config/');
$t1->print("ssid $ssidap1a");
$t1->waitfor('/config/');
$t1->print("no ssid tsunami");
$t1->waitfor('/config/');
$t1->print("authentication open");
$t1->waitfor('/config/');
$t1->print("guest-mode");
$t1->waitfor('/config/');
$t1->print("!");
$t1->waitfor('/config/');
$t1->print("!");
$t1->waitfor('/config/');
$t1->print("end");

#AP 2 Telnet
$t2 = new Net::Telnet ();
$t2->open($ap2);
$t2->waitfor('/Username/');
$t2->print("$un");
$t2->waitfor('/Password:/');
$t2->print("$pw");
$t2->print("enable");
$t2->waitfor('/Password:/');
$t2->print("$pw");
$t2->waitfor('/#/');
$t2->print("Conf term");
$t2->waitfor('/config/');
#sleep 4;
#AP 2 Config
$t2->print("int dot11 0");
$t2->waitfor('/config/');
$t1->print("no ssid tsunami");
$t1->waitfor('/config/');
#sleep 1;
$t2->print("ssid $ssidap2g");
$t2->waitfor('/config/');
$t2->print("authentication open");
$t2->waitfor('/config/');
$t2->print("guest-mode");
$t2->waitfor('/config/');
$t2->print("!");
$t2->waitfor('/config/');
$t2->print("!");
$t2->waitfor('/config/');
$t2->print("int dot11 1");
$t2->waitfor('/config-if/');
$t2->print("no ssid tsunami");
$t2->waitfor('/config/');
$t2->print("ssid $ssidap2a");
$t2->waitfor('/config/');
$t2->print("authentication open");
$t2->waitfor('/config/');
$t2->print("guest-mode");
$t2->waitfor('/config/');
$t2->print("!");
$t2->waitfor('/config/');
$t2->print("!");
$t2->waitfor('/config/');
$t2->print("end");

#AP 3 Telnet
$t3 = new Net::Telnet ();
$t3->open($ap3);
$t3->waitfor('/Username/');
$t3->print("$un");
$t3->waitfor('/Password:/');
$t3->print("$pw");
$t3->print("enable");
$t3->waitfor('/Password:/');
$t3->print("$pw");
$t3->waitfor('/#/');
$t3->print("Conf term");
$t3->waitfor('/config/');

# AP 3 Config
$t3->print("int dot11 0");
$t3->waitfor('/config/');
$t3->print("no ssid tsunami");
$t3->waitfor('/config/');
$t3->print("ssid $ssidap3g");
$t3->waitfor('/config/');
$t3->print("authentication open");
$t3->waitfor('/config/');
$t3->print("guest-mode");
$t3->waitfor('/config/');
$t3->print("!");
$t3->waitfor('/config/');
$t3->print("!");
$t3->waitfor('/config/');
$t3->print("int dot11 1");
$t3->waitfor('/config/');
$t3->print("no ssid tsunami");
$t3->waitfor('/config/');
$t3->print("ssid $ssidap3a");
$t3->waitfor('/config/');
$t3->print("authentication open");
$t3->waitfor('/config/');
$t3->print("guest-mode");
$t3->waitfor('/config/');
$t3->print("!");
$t3->waitfor('/config/');
$t3->print("!");
$t3->waitfor('/config/');
$t3->print("end");

#HTML output goes down here
print "Content-Type: text/html\n\n";
print "<html><HEAD>\n<TITLE>SSID Reset</title></head>\n";
print "<body>\n";
print "Lab SSID's have been reset. <br> $ap1 is configured with $ssidap1g and $ssidap1a.<br>";
print "$ap2 is configured with $ssidap2g and $ssidap2a. <br>";
print "$ap3 is configured with $ssidap3g and $ssidap3a. <br>";
print "\n<p>This page will go back to the main page in 5 seconds<p>\n";
print "\n</body>\n";
print "<meta HTTP-EQUIV=\"REFRESH\" content=\"5; url=/asd/asd_v2.html\">\n";
print "</html>\n";


 

einstein1

Junior Member
May 26, 2005
5
0
0
Dianoic : thanks dude
nweaver : Could u tell me whether this program can be modified for extracting info like ,snmp config , service passwd encryption , ntp , cdp ?
 

secnet

Junior Member
May 27, 2005
5
0
0
Hi can you guys help me out in installing the Net::telnet::cisco module..
I use PPM3. I tried installing it using the command "install Net::telnet:cisco" But it doesnt seem to work..
 

secnet

Junior Member
May 27, 2005
5
0
0
Hi can you guys help me out in installing the Net::telnet::cisco module..
I use PPM3. I tried installing it using the command "install Net::telnet:cisco" But it doesnt seem to work..


Originally posted by: nweaver
use the net::telnet module...I have automated some test lab setups by using perl scripts with this module as CGI scripts.

 

secnet

Junior Member
May 27, 2005
5
0
0
Hi can you guys help me out in installing the Net::telnet::cisco module..
I use PPM3. I tried installing it using the command "install Net::telnet:cisco" But it doesnt seem to work..
 

nweaver

Diamond Member
Jan 21, 2001
6,813
1
0
yes it can be modified to do anything you can do via telnet, which is pretty much anything. It seems the Cisco add on makes things such as paging work better. Cpan examples are a bit rough, but experiment, and use Ethereal to sniff the session and you can figure stuff out easy.