|
static | ipCIDRcheck ($cidr, $ip=null) |
| Check whether an IP address is part of a CIDR. More...
|
|
Definition at line 9 of file Net.php.
◆ ipCIDRcheck()
static SimpleSAML\Utils\Net::ipCIDRcheck |
( |
|
$cidr, |
|
|
|
$ip = null |
|
) |
| |
|
static |
Check whether an IP address is part of a CIDR.
- Parameters
-
string | $cidr | The network CIDR address. |
string | $ip | The IP address to check. Optional. Current remote address will be used if none specified. Do not rely on default parameter if running behind load balancers. |
- Returns
- boolean True if the IP address belongs to the specified CIDR, false otherwise.
- Author
- Andreas Åkre Solberg, UNINETT AS andre.nosp@m.as.s.nosp@m.olber.nosp@m.g@un.nosp@m.inett.nosp@m..no
-
Olav Morken, UNINETT AS olav..nosp@m.mork.nosp@m.en@un.nosp@m.inet.nosp@m.t.no
-
Brook Schofield, GÉANT
-
Jaime Perez, UNINETT AS jaime.nosp@m..per.nosp@m.ez@un.nosp@m.inet.nosp@m.t.no
Definition at line 26 of file Net.php.
References $_SERVER, $i, and $mask.
Referenced by sspmod_negotiate_Auth_Source_Negotiate\checkMask(), and SimpleSAML_Utilities\ipCIDRcheck().
31 if (strpos($cidr,
'/') ===
false) {
35 list ($net,
$mask) = explode(
'/', $cidr);
40 if (strstr($ip,
':') || strstr($net,
':')) {
44 $ip_pack = @inet_pton($ip);
45 $net_pack = @inet_pton($net);
47 if ($ip_pack ===
false || $net_pack ===
false) {
52 $ip_ip = str_split(bin2hex($ip_pack), 8);
53 foreach ($ip_ip as &$value) {
54 $value = hexdec($value);
57 $ip_net = str_split(bin2hex($net_pack), 8);
58 foreach ($ip_net as &$value) {
59 $value = hexdec($value);
62 $ip_ip[0] = ip2long($ip);
63 $ip_net[0] = ip2long($net);
66 for (
$i = 0;
$mask > 0 &&
$i <
sizeof($ip_ip);
$i++) {
70 $iteration_mask =
$mask;
74 $ip_mask = ~((1 << (32 - $iteration_mask)) - 1);
76 $ip_net_mask = $ip_net[
$i] & $ip_mask;
77 $ip_ip_mask = $ip_ip[
$i] & $ip_mask;
79 if ($ip_ip_mask != $ip_net_mask) {
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
The documentation for this class was generated from the following file:
- libs/composer/vendor/simplesamlphp/simplesamlphp/lib/SimpleSAML/Utils/Net.php