#!/bin/sh # Rebuilds subnets with subnetmask to CIDR style # M.W. Baurichter (c) 2005 v.02 if [ $# -lt 1 ]; then clear echo ">> No file given" echo ">> Need file in syntax xxx.xxx.xxx.xxx nnn.nnn.hhh.hhh" echo ">> where xxx.xxx.xxx is IP addresss and nnn.nnn.hhh.hhh is subnet mask" echo "" exit 0; fi if [ -e rebuild.txt ] then mv rebuild.txt rebuild.old fi echo -n "Checking if IP Addresses are valid ..." for i in `awk '{print $1}' $1` do GREP_PARAM="^[[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*" IPF=`echo $i | grep -c $GREP_PARAM` if [ $IPF == 0 ] ; then echo -e "Failed: Invalid IP address ($i)!" exit 1 fi done echo " Done" echo -n "Creating CIDR file ..." for i in `awk ' /255./ {print $1"/"$2} ' $1` do ip=`echo $i|cut -d "/" -f1` cidr=`/usr/local/bin/whatmask $i|grep CIDR|cut -d " " -f4` echo $ip$cidr >> rebuild.txt done echo " Done" echo "File saved as rebuild.txt"