Compare IP address to IPv6 block

前提是你 提交于 2019-12-06 00:35:20

I've written a library to do this sort of IP address comparison.

$ip = IP_Address::factory($ip);
$block = IP_Network_Address::factory($cidr);

return $block->encloses_address($ip);

The class hierarchy is a bit obtuse because it's designed to enable Kohana's transparent extension.

I've not implemented the code to convert an IPv4 address to a special previxed IPv6 address, so you may have to do a small amount of checking before the comparison. Pull requests are of course welcomed :)

As an example I need to see if 194.144.247.254 belongs to 2001:067c:006c::/48 or 2001:1a98::/32 or 217.151.176.18/32 or 217.171.208.0/20.

How can a IPv4 address belong to a IPv6 range? You can only compare the same kind of addresses this way. The other thing makes no sense.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!