Home > Backend Development > PHP Tutorial > 如何看ipv6的地址范围

如何看ipv6的地址范围

WBOY
Release: 2016-06-13 10:33:21
Original
1320 people have browsed it

怎么看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);*/?><br><font color="#e78608">------解决方案--------------------</font><br>
Copy after login
探讨

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
$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


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template