> Hi All,
>> I am trying to figure out this IPv6 stuff here, especially in a script
> I need to generate IPv6 addresses from a list of IPv4 addresses in a
> database. But I am not too sure if I am on the right road or not. Dave
> Wilson gave a good presentation on IPv6 at an AGM a few years ago, but
> I cannot see to find it... maybe its gone.
>> Anyhow, here is a wee function in php to calculate the IPv6 address,
> modified from one I found on hotscripts;
>> function ipv4Toipv6 ($ipv4Address) {
> if(!$ipv4Address) {
> return false;
> }
> list($octet1, $octet2, $octet3, $octet4) = split ("\.", $ipv4Address, 4);
> $decimal = ((((($octet1 * 256 + $octet2) *256 ) + $octet3) * 256 ) +
> $octet4);
> $hex = dechex($decimal);
> $splitHex = str_split($hex, 4);
> $ipv6 = "2002:$splitHex[0]:$splitHex[1]:0:0:0:0:0";
> return $ipv6;
> }
> echo ipv4Toipv6("127.0.0.1");
>> This produces;
>>> 2002:7f00:0001:0:0:0:0:0
>> Which is wrong, firstly the 2002 should be FFFF,
Ermmm - isn't the 2002 bit hardcoded in the code above ? So how can it
be wrong ?
2002:7f00:0001:0:0:0:0:0 (or even 2002:7f00:1::) looks fine to me.
> and secondly the 0001
> I think can have the 0 droped from it. Is this correct?
Indeed it can be compressed to '1' - same way as in IPv4 '127.000.000.001'
gets compressed down to '127.0.0.1'
> I can work
> around the FFFF or the reserved addresses issues, however if I left
> the preceding 0's in would that invaildate any address I enter?
No.
Also - you can replace the trailing '0:0:0:0:0' with '::'
Or you could you install ipv6calc and use it:
dave at freyja:~$ ipv6calc --ipv4_to_6to4addr 127.0.0.1
2002:7f00:1::
Dave
>> If I run my home IP address through this (212.17.57.169) I get
> 2002:d411:39a9:0:0:0:0:0 which appears to be correct.
>> So, I am almost there I think, but alas my understanding of IPv6 is
> very limited, if anyone can point out a few pitfalls of the above way
> and things I need to consider that would be great.
>> Thanks In advance.
> AJ
> --
> Irish Linux Users' Group mailing list
> About this list : http://mail.linux.ie/mailman/listinfo/ilug> Who we are : http://www.linux.ie/> Where we are : http://www.linux.ie/map/>
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!