Difference between revisions of "User:Kir/cidr2wiki.sh"
< User:Kir
(created) |
(No difference)
|
Latest revision as of 15:18, 29 June 2011
cidr2mask() {
local i mask=""
local full_octets=$(($1/8))
local partial_octet=$(($1%8))
for i in 0 1 2 3; do
if [ $i -lt $full_octets ]; then
mask="${mask}255"
elif [ $i -eq $full_octets ]; then
mask="${mask}$((256 - (1 << (8 - $partial_octet))))"
else
mask="${mask}0"
fi
test $i -lt 3 && mask="${mask}."
done
echo $mask
}