Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ip_in_range script IPv6 address has a problem with a IPv6 range #17

Open
C0nw0nk opened this issue Nov 14, 2017 · 1 comment
Open

ip_in_range script IPv6 address has a problem with a IPv6 range #17

C0nw0nk opened this issue Nov 14, 2017 · 1 comment

Comments

@C0nw0nk
Copy link

C0nw0nk commented Nov 14, 2017

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

@gabiu
Copy link

gabiu commented Sep 27, 2021

I have the same issue, if you look at the code, it actually ignores the netmask (/29) and behaves like it would of been /32
I will see if I can provide a patch for this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants