[6bone] ip6 conversion script

Sam Bingner sam@dhs.org
Mon, 2 Sep 2002 01:30:10 -1000


This is a multi-part message in MIME format.

------=_NextPart_000_0003_01C25220.48047D00
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

I attached a little conversion tool written in perl to take as an argument a
regular ip6 address like 3ffe:2900:b::1 and output the ip6.int address and
full ipv6 address.

Don't know if you guys will find a use for it, but trying to figure out what
to put in DNS files gave me a headache ;)

if anybody wants to post it on a website somewhere, feel free... just let me
know :)

Sam

Syntax:

[thanotos@recluce src]# ip6info 3ffe:2900:b001:1::1/64
Full ip6 address: 3ffe:2900:b001:0001:0000:0000:0000:0001
ip6.rev address:
1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1.0.0.0.1.0.0.b.0.0.9.2.e.f.f.3.ip6.int.
ip6.rev prefix (domain): 1.0.0.0.1.0.0.b.0.0.9.2.e.f.f.3.ip6.int
ip6.rev suffix (host):   1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0

or

[thanotos@recluce src]# ip6info 3ffe:2900:b001:1::1
Full ip6 address: 3ffe:2900:b001:0001:0000:0000:0000:0001
ip6.rev address:
1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1.0.0.0.1.0.0.b.0.0.9.2.e.f.f.3.ip6.int.

------=_NextPart_000_0003_01C25220.48047D00
Content-Type: application/octet-stream;
	name="ip6info"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="ip6info"

#!/usr/bin/perl=0A=
#=0A=
#  IPv6 address conversion tool=0A=
#  by Sam Bingner <sam@bingner.com>=0A=
#  Copywrite (c) 2002, Sam Bingner=0A=
=0A=
use strict;=0A=
=0A=
my (@addr6, @ip6, $prefix);=0A=
=0A=
my @addr =3D split(/:/, $ARGV[0]);=0A=
=0A=
unless (length $addr[0]) {=0A=
    shift @addr;=0A=
}=0A=
=0A=
if ($addr[$#addr] =3D~ s/\/(\d{0,3})$//) {=0A=
    $prefix =3D $1;=0A=
}=0A=
=0A=
foreach my $section (@addr) {=0A=
   if (length $section > 0) {=0A=
       push @addr6, sprintf("%04x", hex($section));=0A=
       my @array =3D split(//, $addr6[$#addr6]);=0A=
       for (1..4) {=0A=
          unshift @ip6, shift @array;=0A=
       }=0A=
   } else {=0A=
       for (1..8 - $#addr) {=0A=
          push @addr6, '0000';=0A=
          unshift @ip6, (0,0,0,0);=0A=
       }=0A=
   }=0A=
};=0A=
=0A=
unless (scalar(@addr6) =3D=3D 8) {=0A=
    for ($#addr6..8) {=0A=
        push @addr6, '0000';=0A=
    }=0A=
}=0A=
=0A=
print "Full ip6 address: " . join(':', @addr6) . "\n";=0A=
print "ip6.rev address: " . join('.', @ip6) . ".ip6.int.\n";=0A=
if (defined $prefix) {=0A=
    print "ip6.rev prefix (domain): " . join('.', @ip6[(128 - $prefix) / =
4..$#ip6]) . ".ip6.int\n";=0A=
    print "ip6.rev suffix (host):   " . join('.', @ip6[0..(128 - =
$prefix) / 4 - 1]) . "\n";=0A=
}=0A=

------=_NextPart_000_0003_01C25220.48047D00--