Strange one-word DNS name
Alexander Ottl
aottl at mpmail.net
Thu Feb 22 10:25:55 UTC 2001
Kevin Darcy wrote:
>
> Angus Mackay wrote:
>
> > It would seem that Obi Wan (obiwan at mahood.com) said:
> > > Thanks. Do you know how to convert between the two?
> >
> > the hard way:
> > $ perl -e 'foreach $arg (@ARGV) { $a1 = ($arg & 0xff000000)>>24; $a2 = ($arg & 0xff0000)>>16; $a3 = ($arg & 0xff00)>>8; $a4 = ($arg & 0xff); print "$arg --> $a1.$a2.$a3.$a4\n"; }' 3506561497 1047530039
> > 3506561497 --> 209.1.225.217
> > 1047530039 --> 62.112.10.55
>
> It doesn't have to be *quite* that ugly:
>
> perl -e 'map { printf("%s --> %s\n", $_, join(".", unpack("C4", pack("I", $_)))) } @ARGV' 3506561497 1047530039
>
Well, if we have to throw perl snippets at each other :-)
sub numtoip
{
my($num) = @_;
my @octets = unpack('C4', pack('N', $num));
return join('.', @octets);
}
sub iptonum
{
my($ip) = @_;
my @octets = split(/\./, $ip);
return unpack('N', pack('C4', @octets));
}
sub nummask
{
my($bits) = @_;
my $bitstring = '1' x $bits . '0' x (32-$bits);
my $mask = pack('B32', $bitstring);
return unpack('N', $mask);
}
sub prefixtomask
{
my($prefix) = @_;
return numtoip(nummask($prefix));
}
This was once used to convert ipaddress/prefix notation into whatever
you needed to create the router config and to tell the customer what
ip-addresses to use.
Just to keep this message from being totally off-topic: One could use
the decimal representation of ip addresses in a $GENERATE as offset to
create dummy DNS names that represent the ip address in hexadecimal.
Like:
$GENERATE 0-255 ${167772160,8,x} A 10.0.0.$
Yes, some people use the hex representation of ip addresses as DNS names
--
Alexander Ottl
Media Professionals AG Tel.: +49 (89) 51554-169
Bayerstrasse 21 Fax : +49 (89) 51554-199
D-80335 Muenchen - Germany http://www.media-professionals.de
More information about the bind-users
mailing list