Perl script to update INE CCIE initial configs

I’ve been using INE’s Workbook-1 to study for the routing & switching CCIE. I recently updated my v4 home lab to virtual 1000v routers running on a UCS server(stay tuned for the post). I love the flexibility of the virtual environment and the ability to create new topologies with only the addition of a new sub-interface. This week I started on the BGP labs and quickly found that there are about 15 different initial configs that must be loaded unlike EIGRP and OSPF which had 2 or 3.

The way I connect to the routers is by creating a new sub-interface gig3.193 and applying a reachable address. I think there may be ways to use the serial console in ESX but I like to be able to just telnet directly with my telnet client. Worst thing that could probably happen is I’ll advertise those routes into my lab when redistributing connected.

In order to update the initial configs to what I needed required opening every file for every lab, no-shut gig3, add gig1.193 with the correct IP address per router, dot1q tag and update the VTY lines. I know, doesn’t seem like much, but it was driving me crazy so I wrote a perl script to open all the router configs (not switches) and append the config i needed with the correct IP for the routers. In my case I start at .11 (r1 = .11 r2 = .12 r10 = 20).

So here it is. Hopefully it is of use to others.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
##########################
#!/usr/bin/perl
# Created by Jesse Drohen
# Version 09.30.2014
##########################
# Purpose:
#
# Add custom config into INE CCIE inital configs.
# This has only been tested on a Mac. 
# 
##########################
 
$vlan = '500'; # the vlan your physical switch is expecting
$mask = '255.255.255.192'; # the subnet mask your physical switch is expecting
$baseIP = '10.0.193.'; # the first three octets your physical switch is expecting
 
chdir('./configs') or die "$!"; # place this script in a folder. Then create a subfolder called configs.
                                # Then copy all of the INE folders for each section in the "configs" folder.
 
opendir(DIR, ".") or die "cannot open directory";
@folders = grep(/^[a-z].+/i,readdir(DIR));
closedir(DIR);
 
   foreach $folder (@folders) {
   chomp ($folder);
   @files = ();
 
      chdir("./$folder") or die "$!";
      opendir(DIR, ".") or die "cannot open directory";
      @files = grep(/^r.+/i,readdir(DIR));
      closedir(DIR);
 
         foreach $file (@files) {
         chomp ($file);
         @config = ();
         @finalConfig = ();
 
           open(fileIN,"$file") or dienice("Cannot open $file $!");
           @config = <fileIN>;
           close(fileIN);
           $file =~ s/R//;
           $file =~ s/.txt//;
           $lastOctet = $file + 10;
 
              foreach $line (@config){
              chomp ($line);     
 
              if ($line =~ /^end/) {
              last;
              }
 
              else {
              push(@finalConfig, "$line\n");
              }
 
              }#foreach $line
 
         push(@finalConfig, "interface GigabitEthernet3\n");
         push(@finalConfig, "no shut\n");
         push(@finalConfig, "interface GigabitEthernet3.193\n");
         push(@finalConfig, "encapsulation dot1Q $vlan\n");
         push(@finalConfig, "ip address $baseIP$lastOctet $mask\n");
         push(@finalConfig, "line vty 0 4\n");
         push(@finalConfig, "exec-timeout 0 0\n");
         push(@finalConfig, "privilege level 15\n");
         push(@finalConfig, "password ccie\n");
         push(@finalConfig, "login\n");
         push(@finalConfig, "end\n");
         push(@finalConfig, "end\n");
 
          my $newFile = "updated-R$file.txt";
          open(LOG, ">$newFile") or die "Cannot write to log '$tempLog': $!\n";     	
          print LOG @finalConfig;
          close(LOG);
 
         }#foreach $file
 
	chdir "\.\.";
   }#foreach folder

Author: AustinPixels

Share This Post On

2 Comments

  1. I am a perl beginner and I love the idea of this script but – how do you run it?

    Can’t wait for the post on your virtual lab, I run mine on VMWare on a Dell PC – which works great –

    I also use the virtual console in VMWare so I console to each server. you just need to setup a virtual serial port in VMWARE for each router ping me an email if you want to know more.

    Roger
    UK

  2. Hey Roger, you need to browse to it (Terminal on Mac and CMD.exe on Windows) and once in the folder type “perl script_namp.pl”. You need to have perl installed. It’s installed already on the Mac. You need to install it on a PC. Strawberry Perl is a good choice.

Submit a Comment

Your email address will not be published. Required fields are marked *