classed to classless netmask conversion

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: der.hans
Date:  
Subject: classed to classless netmask conversion
moin, moin,

needed to take a normal dotted quad netmask to classless for something and
thought others might like this little script as well.

I use it as a function, but am including it here as a standalong script.

Send bug reports and enhancements to the list or to :).

#!/bin/bash

classed_2_classless()
{
  decimal='0'
  for i in `echo $1 | tr \. " "`
  do
    if [ $i != '0' ] ; then
      i=`expr $i + 1`
    fi
    decimal=`expr $decimal + $i`
  done
  # classless
  echo `expr $decimal / 32`
}


netmask=$1

classlessmask=`classed_2_classless $netmask`

echo $classlessmask

ciao,

der.hans
--
# home.pages.de/~lufthans/ www.OpNIX.com
# I've got a photographic memory,
# but I'm lousy photographer. - der.hans