Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- ### INCLUDES ###
- ### MAIN CODE BLOCK ###
- ### REPLACEMENT DEFINITIONS ###
- my @r1, @r2, @r3, @r4, @r5, @r6, @bb1, @bb2, @bb3, @sw1, @sw2, @sw3, @sw4;
- my @r1match, @r2match, @r3match, @r4match, @r5match, @r6match, @bb1match, @bb2match, @bb3match, @sw1match, @sw2match, @sw3match, @sw4match, @globalmatch;
- my @r1set, @r2set, @r3set, @r4set, @r5set, @r6set, @bb1set, @bb2set, @bb3set, @sw1set, @sw2set, @sw3set, @sw4set, @globalset;
- #Global
- push (@globalmatch, "clock rate .*");
- push (@globalset, "clock rate 8000000\r");
- push (@globalmatch, "clockrate.*");
- push (@globalset, "clock rate 8000000\r");
- push (@globalmatch, "frame-relay intf-type.*");
- push (@globalset, "\!\r");
- push (@globalmatch, "alias exec en.*");
- push (@globalset, "\!\r");
- push (@globalmatch, "enable secret.*");
- push (@globalset, "enable secret cisco\r");
- push (@globalmatch, "exec-timeout.*");
- push (@globalset, "\!\r");
- #push (@globalmatch, "switchport host");
- #push (@globalset, "switchport mode access");
- #R1
- push (@r1match, "hostname.*");
- push (@r1set, "hostname R1\r");
- push (@r1match, "Serial0\/0\/0");
- push (@r1set, "s0/0");
- push (@r1match, "Serial0\/1\/0");
- push (@r1set, "s0/1");
- #R2
- push (@r2match, "hostname.*");
- push (@r2set, "hostname R2\r");
- push (@r2match, "Serial0\/0\/0");
- push (@r2set, "s0/0");
- push (@r2match, "Serial0\/1\/0");
- push (@r2set, "s0/1");
- #R3
- push (@r3match, "hostname.*");
- push (@r3set, "hostname R3\r");
- #R4
- push (@r4match, "hostname.*");
- push (@r4set, "hostname R4\r");
- push (@r4match, "Serial0\/0\/0");
- push (@r4set, "s0/0");
- push (@r4match, "Serial0\/1\/0");
- push (@r4set, "s0/1");
- #R5
- push (@r5match, "hostname.*");
- push (@r5set, "hostname R5\r");
- push (@r5match, "Serial0\/0\/0");
- push (@r5set, "s0/0");
- push (@r5match, "Serial0\/1\/0");
- push (@r5set, "s0/1");
- #R6
- push (@r6match, "hostname.*");
- push (@r6set, "hostname R6\r");
- push (@r6match, "Serial0\/0\/0");
- push (@r6set, "s0/0");
- #BB1
- push (@bb1match, "hostname.*");
- push (@bb1set, "hostname BB1\r");
- push (@bb1match, "frame-relay switching");
- push (@bb1set, "!\r");
- push (@bb1match, "interface Serial6");
- push (@bb1set, "interface s0/0");
- push (@bb1match, "interface Serial9");
- push (@bb1set, "interface s0/1");
- push (@bb1match, "frame-relay route .*");
- push (@bb1set, "!\r");
- push (@bb1match, "description.*");
- push (@bb1set, "!\r");
- #BB2
- push (@bb2match, "hostname.*");
- push (@bb2set, "hostname BB2\r");
- push (@bb2match, "Ethernet0");
- push (@bb2set, "f0/0");
- push (@bb2match, "description.*");
- push (@bb2set, "!\r");
- #BB3
- push (@bb3match, "hostname.*");
- push (@bb3set, "hostname BB3\r");
- push (@bb3match, "Serial0");
- push (@bb3set, "s0/0");
- push (@bb3match, "Ethernet0");
- push (@bb3set, "f0/0");
- push (@bb3match, "description.*");
- push (@bb3set, "!\r");
- #SW1
- push (@sw1match, "hostname.*");
- push (@sw1set, "hostname SW1\r");
- #SW2
- push (@sw2match, "hostname.*");
- push (@sw2set, "hostname SW2\r");
- #SW3
- push (@sw3match, "hostname.*");
- push (@sw3set, "hostname SW3\r");
- #SW4
- push (@sw4match, "hostname.*");
- push (@sw4set, "hostname SW4\r");
- ### Open original data files
- open (INPUT, "r1.txt") || die ("Could not open r1.txt!\r\r");
- @r1 = <INPUT>;
- open (INPUT, "r2.txt") || die ("Could not open r2.txt!\r\r");
- @r2 = <INPUT>;
- open (INPUT, "r3.txt") || die ("Could not open r3.txt!\r\r");
- @r3 = <INPUT>;
- open (INPUT, "r4.txt") || die ("Could not open r4.txt!\r\r");
- @r4 = <INPUT>;
- open (INPUT, "r5.txt") || die ("Could not open r5.txt!\r\r");
- @r5 = <INPUT>;
- open (INPUT, "r6.txt") || die ("Could not open r6.txt!\r\r");
- @r6 = <INPUT>;
- open (INPUT, "bb1.txt") || die ("Could not open bb1.txt!\r\r");
- @bb1 = <INPUT>;
- open (INPUT, "bb2.txt") || die ("Could not open bb2.txt!\r\r");
- @bb2 = <INPUT>;
- open (INPUT, "bb3.txt") || die ("Could not open bb3.txt!\r\r");
- @bb3 = <INPUT>;
- open (INPUT, "sw1.txt") || die ("Could not open sw1.txt!\r\r");
- @sw1 = <INPUT>;
- open (INPUT, "sw2.txt") || die ("Could not open sw2.txt!\r\r");
- @sw2 = <INPUT>;
- open (INPUT, "sw3.txt") || die ("Could not open sw3.txt!\r\r");
- @sw3 = <INPUT>;
- open (INPUT, "sw4.txt") || die ("Could not open sw4.txt!\r\r");
- @sw4 = <INPUT>;
- #R1
- my @newFile;
- foreach $line (@r1) {
- chomp ($line);
- for ($n = 0; $n < @r1match; $n++) {
- $line =~ s/$r1match[$n]/$r1set[$n]/;
- }
- for ($n = 0; $n < @globalmatch; $n++) {
- $line =~ s/$globalmatch[$n]/$globalset[$n]/;
- }
- push (@newFile, $line);
- }
- @r1 = @newFile;
- #R2
- my @newFile;
- foreach $line (@r2) {
- chomp ($line);
- for ($n = 0; $n < @r2match; $n++) {
- $line =~ s/$r2match[$n]/$r2set[$n]/;
- }
- for ($n = 0; $n < @globalmatch; $n++) {
- $line =~ s/$globalmatch[$n]/$globalset[$n]/;
- }
- push (@newFile, $line);
- }
- @r2 = @newFile;
- #R3
- my @newFile;
- foreach $line (@r3) {
- chomp ($line);
- for ($n = 0; $n < @r3match; $n++) {
- $line =~ s/$r3match[$n]/$r3set[$n]/;
- }
- for ($n = 0; $n < @globalmatch; $n++) {
- $line =~ s/$globalmatch[$n]/$globalset[$n]/;
- }
- push (@newFile, $line);
- }
- @r3 = @newFile;
- #R4
- my @newFile;
- foreach $line (@r4) {
- chomp ($line);
- for ($n = 0; $n < @r4match; $n++) {
- $line =~ s/$r4match[$n]/$r4set[$n]/;
- }
- for ($n = 0; $n < @globalmatch; $n++) {
- $line =~ s/$globalmatch[$n]/$globalset[$n]/;
- }
- push (@newFile, $line);
- }
- @r4 = @newFile;
- #R5
- my @newFile;
- foreach $line (@r5) {
- chomp ($line);
- for ($n = 0; $n < @r5match; $n++) {
- $line =~ s/$r5match[$n]/$r5set[$n]/;
- }
- for ($n = 0; $n < @globalmatch; $n++) {
- $line =~ s/$globalmatch[$n]/$globalset[$n]/;
- }
- push (@newFile, $line);
- }
- @r5 = @newFile;
- #R6
- my @newFile;
- foreach $line (@r6) {
- chomp ($line);
- for ($n = 0; $n < @r6match; $n++) {
- $line =~ s/$r6match[$n]/$r6set[$n]/;
- }
- for ($n = 0; $n < @globalmatch; $n++) {
- $line =~ s/$globalmatch[$n]/$globalset[$n]/;
- }
- push (@newFile, $line);
- }
- @r6 = @newFile;
- #BB1
- my @newFile;
- $omit = 0;
- foreach $line (@bb1) {
- chomp ($line);
- if ($line =~ /interface Serial0.*/) { $omit = 1;}
- if ($line =~ /interface\ Serial6.*/) { $omit = 0;}
- if ($line =~ /interface\ Serial7.*/) { $omit = 1;}
- if ($line =~ /interface\ Serial9.*/) { $omit = 0;}
- for ($n = 0; $n < @bb1match; $n++) {
- $line =~ s/$bb1match[$n]/$bb1set[$n]/;
- }
- for ($n = 0; $n < @globalmatch; $n++) {
- $line =~ s/$globalmatch[$n]/$globalset[$n]/;
- }
- if ($omit ne 1) { push (@newFile, $line); }
- }
- @bb1 = @newFile;
- #BB2
- my @newFile;
- foreach $line (@bb2) {
- chomp ($line);
- for ($n = 0; $n < @bb2match; $n++) {
- $line =~ s/$bb2match[$n]/$bb2set[$n]/;
- }
- for ($n = 0; $n < @globalmatch; $n++) {
- $line =~ s/$globalmatch[$n]/$globalset[$n]/;
- }
- push (@newFile, $line);
- }
- @bb2 = @newFile;
- #BB3
- my @newFile;
- foreach $line (@bb3) {
- chomp ($line);
- for ($n = 0; $n < @bb3match; $n++) {
- $line =~ s/$bb3match[$n]/$bb3set[$n]/;
- }
- for ($n = 0; $n < @globalmatch; $n++) {
- $line =~ s/$globalmatch[$n]/$globalset[$n]/;
- }
- push (@newFile, $line);
- }
- @bb3 = @newFile;
- #SW1
- my @newFile;
- foreach $line (@sw1) {
- chomp ($line);
- for ($n = 0; $n < @sw1match; $n++) {
- $line =~ s/$sw1match[$n]/$sw1set[$n]/;
- }
- for ($n = 0; $n < @globalmatch; $n++) {
- $line =~ s/$globalmatch[$n]/$globalset[$n]/;
- }
- push (@newFile, $line);
- }
- @sw1 = @newFile;
- #SW2
- my @newFile;
- foreach $line (@sw2) {
- chomp ($line);
- for ($n = 0; $n < @sw2match; $n++) {
- $line =~ s/$sw2match[$n]/$sw2set[$n]/m;
- }
- for ($n = 0; $n < @globalmatch; $n++) {
- $line =~ s/$globalmatch[$n]/$globalset[$n]/m;
- }
- push (@newFile, $line);
- }
- @sw2 = @newFile;
- #SW3
- my @newFile;
- foreach $line (@sw3) {
- chomp ($line);
- for ($n = 0; $n < @sw3match; $n++) {
- $line =~ s/$sw3match[$n]/$sw3set[$n]/m;
- }
- for ($n = 0; $n < @globalmatch; $n++) {
- $line =~ s/$globalmatch[$n]/$globalset[$n]/m;
- }
- push (@newFile, $line);
- }
- @sw3 = @newFile;
- #SW4
- my @newFile;
- foreach $line (@sw4) {
- chomp ($line);
- for ($n = 0; $n < @sw4match; $n++) {
- $line =~ s/$sw4match[$n]/$sw4set[$n]/m;
- }
- for ($n = 0; $n < @globalmatch; $n++) {
- $line =~ s/$globalmatch[$n]/$globalset[$n]/m;
- }
- push (@newFile, $line);
- }
- @sw4 = @newFile;
- # ADD SOME GLOBAL COMMANDS
- #$routerGlobal = "conf t\rint ra f0/0 , f0/1\rspeed 100\rduplex full\rend\r\r\r";
- #$switchGlobal = "conf t\rint ra f1/1 - 15\rspeed 100\rduplex full\rline con 0\rexec-timeout 0\rend\r\r\r";
- push (@r1, $routerGlobal);
- push (@r2, $routerGlobal);
- push (@r3, $routerGlobal);
- push (@r4, $routerGlobal);
- push (@r5, $routerGlobal);
- push (@r6, $routerGlobal);
- push (@bb1, $routerGlobal);
- push (@bb2, $routerGlobal);
- push (@bb3, $routerGlobal);
- push (@sw1, $switchGlobal);
- push (@sw2, $switchGlobal);
- push (@sw3, $switchGlobal);
- push (@sw4, $switchGlobal);
- # WRITE FILES
- open (OUTFILE, ">R1-converted.cfg") || die ("Could not open file for writing!\r\r");
- print OUTFILE "\r\r\r\ren\rconfig t\r";
- print OUTFILE @r1;
- open (OUTFILE, ">R2-converted.cfg") || die ("Could not open file for writing!\r\r");
- print OUTFILE "\r\r\r\ren\rconfig t\r";
- print OUTFILE @r2;
- open (OUTFILE, ">R3-converted.cfg") || die ("Could not open file for writing!\r\r");
- print OUTFILE "\r\r\r\ren\rconfig t\r";
- print OUTFILE @r3;
- open (OUTFILE, ">R4-converted.cfg") || die ("Could not open file for writing!\r\r");
- print OUTFILE "\r\r\r\ren\rconfig t\r";
- print OUTFILE @r4;
- open (OUTFILE, ">R5-converted.cfg") || die ("Could not open file for writing!\r\r");
- print OUTFILE "\r\r\r\ren\rconfig t\r";
- print OUTFILE @r5;
- open (OUTFILE, ">R6-converted.cfg") || die ("Could not open file for writing!\r\r");
- print OUTFILE "\r\r\r\ren\rconfig t\r";
- print OUTFILE @r6;
- open (OUTFILE, ">BB1-converted.cfg") || die ("Could not open file for writing!\r\r");
- print OUTFILE "\r\r\r\ren\rconfig t\r";
- print OUTFILE @bb1;
- open (OUTFILE, ">BB2-converted.cfg") || die ("Could not open file for writing!\r\r");
- print OUTFILE "\r\r\r\ren\rconfig t\r";
- print OUTFILE @bb2;
- open (OUTFILE, ">BB3-converted.cfg") || die ("Could not open file for writing!\r\r");
- print OUTFILE "\r\r\r\ren\rconfig t\r";
- print OUTFILE @bb3;
- open (OUTFILE, ">SW1-converted.cfg") || die ("Could not open file for writing!\r\r");
- print OUTFILE "\r\r\r\ren\rconfig t\r";
- print OUTFILE @sw1;
- open (OUTFILE, ">SW2-converted.cfg") || die ("Could not open file for writing!\r\r");
- print OUTFILE "\r\r\r\ren\rconfig t\r";
- print OUTFILE @sw2;
- open (OUTFILE, ">SW3-converted.cfg") || die ("Could not open file for writing!\r\r");
- print OUTFILE "\r\r\r\ren\rconfig t\r";
- print OUTFILE @sw3;
- open (OUTFILE, ">SW4-converted.cfg") || die ("Could not open file for writing!\r\r");
- print OUTFILE "\r\r\r\ren\rconfig t\r";
- print OUTFILE @sw4;
- system ('gedit R1-converted.cfg &');
- select(undef, undef, undef, 0.3);
- system ('gedit R2-converted.cfg &');
- select(undef, undef, undef, 0.1);
- system ('gedit R3-converted.cfg &');
- select(undef, undef, undef, 0.1);
- system ('gedit R4-converted.cfg &');
- select(undef, undef, undef, 0.1);
- system ('gedit R5-converted.cfg &');
- select(undef, undef, undef, 0.1);
- system ('gedit R6-converted.cfg &');
- select(undef, undef, undef, 0.1);
- system ('gedit SW1-converted.cfg &');
- select(undef, undef, undef, 0.1);
- system ('gedit SW2-converted.cfg &');
- select(undef, undef, undef, 0.1);
- system ('gedit SW3-converted.cfg &');
- select(undef, undef, undef, 0.1);
- system ('gedit SW4-converted.cfg &');
- select(undef, undef, undef, 0.1);
- system ('gedit BB1-converted.cfg &');
- select(undef, undef, undef, 0.1);
- system ('gedit BB2-converted.cfg &');
- select(undef, undef, undef, 0.1);
- system ('gedit BB3-converted.cfg &');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement