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

Bug - is Ip in range evaluated as false #354

Open
kibwashere opened this issue Apr 27, 2022 · 0 comments
Open

Bug - is Ip in range evaluated as false #354

kibwashere opened this issue Apr 27, 2022 · 0 comments

Comments

@kibwashere
Copy link

I created the following range IP: 194.214.29.0-194.214.29.255
Which is converted to the following binary IP: ["111101001010011110001100000000", "111101001010011110001000000001"] (from the calculateIp function here

private function calculateIp(string $ip)
)

Now, when my laptop IP is on 194.214.29.197, the associated binary IP is: 1111010010100111100010001110111

The function isIpInRange returns false (here:

&& $calculatedIpRange[0] <= $currentIp && $currentIp <= $calculatedIpRange[1]
)
So 194.214.29.0 < 194.214.29.197 < 194.214.29.255 is true
but range binary IP 1 < my binary IP < range binary IP 2 is not true
because my binary IP has an extra bit 31 instead of 30?

As a temporary solution (I think it's working), I updated your condition from:

if ($calculatedIpRange[0] !== false && $calculatedIpRange[1] !== false
  && $calculatedIpRange[0] <= $currentIp && $currentIp <= $calculatedIpRange[1]
  ) {

to

if (($calculatedIpRange[0] !== false && $calculatedIpRange[1] !== false
  && $calculatedIpRange[0] <= $currentIp && $currentIp <= $calculatedIpRange[1]
  ) || ($calculatedIpRange[0] > $calculatedIpRange[1] && $calculatedIpRange[0] !== false && $calculatedIpRange[1] !== false
  && $calculatedIpRange[1] <= $currentIp && $currentIp <= $calculatedIpRange[0])) {

Let me know your thoughts, not sure this is a nice way to fix this
Thanks,

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

1 participant