21 lines
398 B
Bash
21 lines
398 B
Bash
mask2cidr() {
|
|
local netmask=$1
|
|
local nbits=0
|
|
IFS=.
|
|
for dec in $netmask; do
|
|
case $dec in
|
|
255) let nbits+=8;;
|
|
254) let nbits+=7;;
|
|
252) let nbits+=6;;
|
|
248) let nbits+=5;;
|
|
240) let nbits+=4;;
|
|
224) let nbits+=3;;
|
|
192) let nbits+=2;;
|
|
128) let nbits+=1;;
|
|
0);;
|
|
*) die "Error: $dec is not recognised"
|
|
esac
|
|
done
|
|
echo "$nbits"
|
|
}
|