Created
February 11, 2015 09:54
-
-
Save akeinhell/bb753db7cc0e5a7d04b2 to your computer and use it in GitHub Desktop.
Проверка IP В диапазоне
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function matchCIDR($addr,$cidr) { | |
list($ip,$mask) = explode('/',$cidr); | |
return (ip2long($addr) >> (32 - $mask) == ip2long($ip) >> (32 - $mask)); | |
} | |
function cidr_match($ip, $range) | |
{ | |
list ($subnet, $bits) = explode('/', $range); | |
$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; | |
} | |
matchCIDR ("192.168.1.200", "192.168.1.150/25"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment