diff --git a/globals/Dependencies/Web/IpRange.php b/globals/Dependencies/Web/IpRange.php new file mode 100644 index 0000000..29c2e05 --- /dev/null +++ b/globals/Dependencies/Web/IpRange.php @@ -0,0 +1,88 @@ += $lower_dec) && ($ip_dec <= $upper_dec)); + } + + return false; + } + } + + public static function IsIpInCidrRange(string $ip, string $cidr) + { + list($subnet, $bits) = explode('/', $cidr); + if ($bits === null) { + $bits = 32; + } + $ip = ip2long($ip); + $subnet = ip2long($subnet); + $mask = -1 << (32 - $bits); + $subnet &= $mask; # nb: in case the supplied subnet wasn't correctly aligned + return ($ip & $mask) == $subnet; + } + } +}