classed to classless netmask conversion

トップ ページ
添付ファイル:
Eメールのメッセージ
+ (text/plain)
このメッセージを削除
このメッセージに返信
著者: der.hansPLUGd@LuftHans.com
日付:  
題目: 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