Skip to content

Instantly share code, notes, and snippets.

@atoa
Created May 8, 2013 19:41
Show Gist options
  • Save atoa/5543069 to your computer and use it in GitHub Desktop.
Save atoa/5543069 to your computer and use it in GitHub Desktop.
shell pipeline to convert a Linux routing table to a prefix based network address CSV. depends on having ipcalc installed.
netstat -rn | grep UG | awk '{print $1 " " $3 " " $2 " " $8}' | \
xargs -n4 sh -c 'ipcalc -p -n $0 $1 ; echo $2 $3' | xargs -n4 | \
sed -e 's/PREFIX=\([0-9]\{1,\}\) NETWORK=\([0-9\.]\{1,\}\)/\2\/\1/; s/ /, /g ' | \
sort -V
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment