Skip to content

Instantly share code, notes, and snippets.

@mjf
Created August 3, 2012 07:54
Show Gist options
  • Save mjf/3245562 to your computer and use it in GitHub Desktop.
Save mjf/3245562 to your computer and use it in GitHub Desktop.
Add IPv4 default route to the output of sipcalc(1)
#! /usr/bin/awk -f
# Add IPv4 default route to the output of sipcalc(1)
# Copyright (C) 2009 Matous Jan Fialka, <http://mjf.cz/>
# Released under the terms of The MIT License
#
# Parse output of sipcalc(1) and add default route value
# to the output stream if prefix length is less or equal to 30.
# If prefix length equals to 30 then the lower usable address
# is added as default route, the highest usable address is
# added otherwise.
#
# Usage: sipcalc <net>[/<mask>] | sipcalc-add-ipv4-default-route.awk
{ print }
/^Network mask \(bits\)/ {
prefix_length = $5
}
/^Usable range/ {
if(prefix_length > 30)
next
printf("Default route (gateway)\t- %s\n",
prefix_length == 30 ? $4 : $6)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment