[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: What is the 8 in 10.0.0.0/8 and how can I compute it for mynetwork?
On Tue, 14 Mar 2000, Shaul Karl wrote:
> Any pointer and/or full explanation about the 8 in 10.0.0.0/8 and the way to
> compute it for my network?
> I guess that it has much to do with the subnet mask but isn't subnet masks of
> the form 255.255.0.0?
I attached a shell script that I got from someone, which translates CIDR
into subnet mask notation.
An example of usage:
ariel@fireaxe:~> cidr2dot 132.66.0.0/16
132.66.0.0/255.255.0.0
--Ariel
> --
> Shaul Karl shaulk@israsrv.net.il
> An elephant is a mouse with an operating system.
>
>
>
> =================================================================
> To unsubscribe, send mail to linux-il-request@linux.org.il with
> the word "unsubscribe" in the message body, e.g., run the command
> echo unsubscribe | mail linux-il-request@linux.org.il
>
--
Ariel Biener
e-mail: ariel@post.tau.ac.il Work phone: 03-6406086
fingerprint = 07 D1 E5 3E EF 6D E5 82 0B E9 21 D4 3C 7D 8B BC
#!/bin/bash -f
#
# Created by Ian Farmer
#
argv=`echo $*|awk -F/ '{print NF}'`
argv1=`echo $*|awk -F/ '$1!="" {print $1}'`
argv2=`echo $*|awk -F/ '$2!="" {print $2}'`
unset addr mask
if [ $argv -eq 1 ]; then
if ( $argv1 -lt 0 || $argv1 -gt 32 ) then
echo "CIDR is between 0 and 32."
exit 1
else
mask=$argv1
fi
elif [ $argv -eq 2 ]; then
if ( test $argv2 -lt 0 || test $argv2 -gt 32 ) then
echo "CIDR is between 0 and 32."
exit 1
else
addr=$argv1
mask=$argv2
fi
else
echo "Synopsis: $0 network/cidr or $0 cidr"
fi
unset c n tc smask ; tc=0
if [ "x${mask}" != "x" ]; then
while [ ${tc} -lt 4 ]; do
unset m ; c=0
while [ ${c} -lt 8 ]; do
if [ ${mask} -gt 0 ]; then
m="${m}1"
mask=`expr ${mask} - 1`
else
m="${m}0"
fi
c=`expr ${c} + 1`
done
m=`/bin/echo "obase=10\nibase=2\n${m}" | bc`
if [ ${tc} -gt 0 ]; then
smask="${smask}."
fi
smask="${smask}${m}"
tc=`expr ${tc} + 1` # incrementing the primary while
done
if [ "x${addr}" != "x" ]; then
echo ${addr}/${smask}
else
echo ${smask}
fi
fi