日期:2014-05-17  浏览次数:20734 次

怎么看ipv6的地址范围啊
我不会看ipv6的地址范围,比如下面这两个地址范围是指从哪个地址到哪个地址啊?
2406:6200::|32
240e:100::|24
为什么平时的ip库都是分开的,放在同一个表中会有什么问题吗?

------解决方案--------------------
这都是16进制表示,2字节一个:。

::表示接下来的都是0.

mysql还是可以操作的,unhex啊,substring,replace啊,看你需求了。
------解决方案--------------------
IP地址是可以按照字符串比较大小的, 要计算范围内的每一个IP, 可以gmp/bc直接当做大数运算, 我说的是PHP, 你有需求可以给你写个示例?
------解决方案--------------------
PHP code
[User:root Time:09:54:16 Path:/home/liangdong/php]$ php ip.php 
2406:6200:0000:0000:0000:0000:0000:0000[User:root Time:09:54:17 Path:/home/liangdong/php]$ cat ip.php 
<?php
$ipv6_start = "2406:6200::";
$ipv6_end = "240e:100::";

// 扩展ipv6格式方便阅读
$bin_start = inet_pton($ipv6_start);
$bin_end = inet_pton($ipv6_end);
$start = unpack('H*0', $bin_start)[0];
$start = str_split($start, 4);
$start = implode(":", $start);
echo $start;

/* 作为大数运算, 可以遍历start, end内所有IP地址
$start = gmp_init($start, 16);
$end = unpack('H*0', $bin_end)[0];
$end = gmp_init($end, 16);
echo gmp_strval($start, 16);
*/
?>

------解决方案--------------------
探讨

PHP code
[User:root Time:09:54:16 Path:/home/liangdong/php]$ php ip.php
2406:6200:0000:0000:0000:0000:0000:0000[User:root Time:09:54:17 Path:/home/liangdong/php]$ cat ip.php
<?php
$ipv6_start = "2……

------解决方案--------------------
2400:ff00::|32
应该是从
2400:ff00:0000:0000:0000:0000:0000:0000

2400:ff00:0000:0000:0000:0000:ffff:ffff
后面的CIDR是位数, 32位就是ffff:ffff