to be sure that only people in a certain room are able to
access the quiz.</p>
-<p>For example: <b>192.168. , 231.54.211.0/20, 231.3.56.211</b></p>
+<p>For example: <b>192.168. , 231.54.211.0/20, 231.3.56.211, 231.3.56.10-20</b></p>
-<p>There are three types of numbers you can use (you can not use
- text based domain names like example.com):
+<p>There are four types of numbers you can use (you can not use
+ text based domain names like example.com):</p>
+
<ol>
<li>Full IP addresses, such as <b>192.168.10.1</b> which will match
a single computer (or proxy).</li>
starting with those numbers.</li>
<li>CIDR notation, such as <b>231.54.211.0/20</b> which allows you to specify
more detailed subnets.</li>
+<li>A range of IP addresses <b>231.3.56.10-20</b> The range applies to the last
+ part of the address, so this means all the IP addresses from 231.3.56.10
+ to 231.3.56.20.</li>
</ol>
-</p>
<p>Spaces are ignored.</p>
* Function to check the passed address is within the passed subnet
*
* The parameter is a comma separated string of subnet definitions.
- * Subnet strings can be in one of two formats:
+ * Subnet strings can be in one of three formats:
* 1: xxx.xxx.xxx.xxx/xx
* 2: xxx.xxx
+ * 3: xxx.xxx.xxx.xxx-xxx //a range of IP addresses in the last group.
* Code for type 1 modified from user posted comments by mediator at
* {@link http://au.php.net/manual/en/function.ip2long.php}
*
foreach ($subnets as $subnet) {
$subnet = trim($subnet);
if (strpos($subnet, '/') !== false) { /// type 1
-
list($ip, $mask) = explode('/', $subnet);
$mask = 0xffffffff << (32 - $mask);
$found = ((ip2long($addr) & $mask) == (ip2long($ip) & $mask));
-
+ } else if (strpos($subnet, '-') !== false) {/// type 3
+ $subnetparts = explode('.', $subnet);
+ $addrparts = explode('.', $addr);
+ $subnetrange = explode('-', array_pop($subnetparts));
+ if (count($subnetrange) == 2) {
+ $lastaddrpart = array_pop($addrparts);
+ $found = ($subnetparts == $addrparts &&
+ $subnetrange[0] <= $lastaddrpart && $lastaddrpart <= $subnetrange[1]);
+ }
} else { /// type 2
$found = (strpos($addr, $subnet) === 0);
}
break;
}
}
-
return $found;
}