Skip to content

Instantly share code, notes, and snippets.

@slywalker
Created April 27, 2010 06:27
Show Gist options
  • Save slywalker/380409 to your computer and use it in GitHub Desktop.
Save slywalker/380409 to your computer and use it in GitHub Desktop.
<?php
function checkIPMask($ip, $mask) {
list($maskIp, $maskBit) = explode('/', $mask);
$maskIpLong = ip2long($maskIp) >> (32 - $maskBit);
$ipLong = ip2long($ip) >> (32 - $maskBit);
if ($maskIpLong !== $ipLong) {
return false;
}
return true;
}
$mask = '210.161.126.144/28';
$ip = '210.161.126.144';
var_dump(checkIPMask($ip, $mask));
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment