-
Notifications
You must be signed in to change notification settings - Fork 37
Open
Description
So with the ip_in_range functions i tested both IPv4 and IPv6 and IPv4 seems to be functioning fine but IPv6 seems to have a problem with the IP and range i provided it.
IP and range provided.
$ip = "2a02:c7f:9e03:1d00:59c2:3083:c23b:7146";
$range_ip = "2a02:c78::/29";
Also yes i did add my own function to make it easier to use for ipv4 and ipv6 so it can tell the difference between the two. (hopefully it gets added to the main script for easier use)
function ip_range_type($range_ip)
{
if (strpos($range_ip, ':') !== false) {
//if ip range provided is ipv6 then
//echo "range provided is ipv6";
return 1;
} else {
//if ip range provided is ipv4 then
//echo "range provided is ipv4";
return 2;
}
}
function ip_in_range($ip, $range_ip)
{
//only check IPv4 addresses against IPv4 ranges
if(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) && ip_range_type($range_ip) == 2) {
return ipv4_in_range($ip, $range_ip);
}
//only check IPv6 addresses against IPv6 ranges
if(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) && ip_range_type($range_ip) == 1) {
return ipv6_in_range($ip, $range_ip);
}
}
Online example :
https://3v4l.org/h5psU
I don't know why that range is incorrect if you look up the details on that users IP it provides that as a valid range.
http://ipinfo.io/2a02:c7f:9e03:1d00:59c2:3083:c23b:7146
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels