Skip to content

Instantly share code, notes, and snippets.

@mattpascoe
Created November 6, 2012 20:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattpascoe/4027169 to your computer and use it in GitHub Desktop.
Save mattpascoe/4027169 to your computer and use it in GitHub Desktop.
Generate DCM.PL commands from the output of a 'show ip route' to load into ONA
#!/bin/bash
#
# Author: Matt Pascoe - matt@opennetadmin.com
#
# usage: ./parseshowroute.sh <filename>
#
# Takes the output of a "show ip route" command from an IOS device
# and processes it. Simply get the output and save it to a file
# and then run this script against that file.
#
# It will output dcm.pl command syntax to create a new subnet based
# on the route. The default subnet type will simply be 'LAN', please
# change that to an appropriate value if needed. Also the default
# subnet name will be 'SHOWROUTE-<IP>' to indicate it was created by
# this script. In all cases a new name should be determined.
#
# Another major point, not all routes equate to actual subnets. Some
# routes are summarized so that one route will include multiple
# subnets. Be sure to examine these as it will cause overlaps while
# loading the data. I would suggest anything with a larger mask than
# /24 should be investigated.
#
# The major goal of this is to initially populate ONA with subnets
# that you can then load hosts and interfaces into. It is step one
# in the process of adding data to ONA.
cat $1 | \
sed -e "s/EX//"| \
awk '{print $2}'| \
grep /| \
sed -e "s/\(.*\)\/\(.*\)/dcm.pl -r subnet_add ip=\1 netmask=\/\2 name='SHOWROUTE-\1' type='LAN'/"| \
egrep -v "\/0|\/32"| \
sort -t, -n -r --key=4| \
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment