James,
Honestly when I initially wrote these conversions I had hoped
that someone would provide a much simpler way of doing them.
I was surprised that there wasn't a standard OS command to do
the conversions for you.
That being said, your method is absolutely brilliant. Thanks!
With respect to the default cidr=/24, I meant to condition both
directions of conversion to throw an error if the inputs exceeded
boundary conditions. However as you can see I forgot to get
around to that. Now I will get it into 1.8.1 thanks to your
contribution.
Brad
On Thu, 2007-01-25 at 09:27 -0500, James Carlson wrote:
> Graham Hares writes:
> > if [ $oct1 -lt 128 ]&&[ $oct2 -eq 0 ]&&[ $oct3 -eq 0 ]&&[ $oct4
> > -eq 0 ];then cidr=0;
>
> You can do most of this with:
>
> perl -e 'use Socket; print unpack("%32b*",inet_aton($ARGV[0])), "\n";' $nm
>
> If you really want to make sure that unsupported non-contiguous
> netmasks are all transformed into /24 as this script does (not sure
> why that's a good thing), then:
>
> perl -e 'use Socket;
> $addr = inet_aton($ARGV[0]);
> $bits = unpack("%32b*",$addr);
> $contig = pack("N",~((1<<(32-$bits))-1));
> print (($contig eq $addr ? $bits : 24), "\n");' $nm
>
> > cidr2dot() {
> > cidr=$1
> > if [ $cidr -ge 32 ];then netmask='255.255.255.255'
>
> Similarly:
>
> perl -e 'use Socket;
> ($c1,$c2,$c3,$c4) = unpack("C4",pack("N",~((1<<(32-$ARGV[0]))-1)));
> print "$c1.$c2.$c3.$c4\n";' $cidr
>
> There probably ought to be better ways of handling IP values in your
> shell of choice.
>
_______________________________________________
zones-discuss mailing list
[email protected]