[英]PHP how to check if IP RANGE provided is IPv4 or IPv6
So I have the following two IP ranges所以我有以下两个 IP 范围
2a02:c78::/29
2.120.0.0/13
What php function can i use to tell the difference between a ipv4 range and a ipv6 range我可以使用什么 php 函数来区分 ipv4 范围和 ipv6 范围
Need something like this需要这样的东西
function ip_range_type($range_ip)
{
//if ip range provided is ipv4 then
//if ip range provided is ipv6 then
}
Credit for this solution goes to user @deceze此解决方案归功于用户@deceze
function ip_range_type($range_ip)
{
if (strpos($range_ip, ':') !== false) {
//if ip range provided is ipv6 then
echo "range provided is ipv6";
} else {
//if ip range provided is ipv4 then
echo "range provided is ipv4";
}
}
$range_ip = "2a02:c78::/29";
ip_range_type($range_ip);
IP addresses has a lot of Ranges like All IPv4 Ranges with network addresses & CIDR same you can check for IPv6 Ranges too. IP 地址有很多范围,例如具有网络地址和 CIDR 的所有IPv4 范围,您也可以检查IPv6 范围。 Answer of your question is already explained here check IPv4 or IPv6 Range with an efficient way.您的问题的答案已在此处解释,以有效的方式检查 IPv4 或 IPv6 范围。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.