[nsp] Script to check for IOS interface settings

John Kristoff jtk at northwestern.edu
Thu Jun 10 22:37:18 EDT 2004


I thought someone might find this help.  Below is a simple script to
find if a particular configuration option that is or is not set on an
interface.  An example might be to check for standard ingress/egress
ACLs.  Pass a interface configuration statement (quote and use regex
as appropriate) and a stored configuration file on the command line.

This appears to work for me, but if someone finds bugs or wants to
send me minor improvements I'll keep an updated copy here:

  http://aharp.ittns.northwestern.edu/software/ios-ifcheck>

I hereby place this script in the public domain:

  #!/usr/bin/perl -wT
  use strict;
  $| = 1;

  # ios-ifcheck - check IOS config for interface commands
  #
  # 2004-06-10,jtk: new

  if ($#ARGV+1 != 2) {
    print "Usage: $0 \"interface command to check\" config-file\n";
    exit (1);
  }

  my $search_option = shift;
  my $config = shift;
  my %interface = ();
  my $interface_sepator = "!\n";
  $/=$interface_sepator;

  open( FILE, "< $config" ) or die "Can't open $config: $!\n";

  while (defined(my $line = <FILE>)) {
      chomp $line;
      my @interface = split(/\n/m, $line);

      if ($line !~ /^interface \S+.?[0-9]*\n/) {
          next;   # not an interface record
      }

      print "$interface[0]\n";
      my $interface_statement = "";
      foreach $interface_statement (@interface[1..$#interface]) {
         if ($interface_statement =~ /$search_option/) {
             print "  $interface_statement\n";
             next;
         }
      }
  }

John


More information about the cisco-nsp mailing list