-
Notifications
You must be signed in to change notification settings - Fork 701
Expand file tree
/
Copy pathNet.php
More file actions
35 lines (30 loc) · 1022 Bytes
/
Net.php
File metadata and controls
35 lines (30 loc) · 1022 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
declare(strict_types=1);
namespace SimpleSAML\Utils;
use Symfony\Component\HttpFoundation\IpUtils;
use Symfony\Component\HttpFoundation\Request;
/**
* Net-related utility methods.
*
* @deprecated This class will be removed in a next major release. Use Symfony IpUtils instead.
* @package SimpleSAMLphp
*/
class Net
{
/**
* Check whether an IP address is part of a CIDR.
*
* @param string|array $cidr The network CIDR address.
* @param string|null $ip The optional IP address to check. Current remote address will be used if none specified.
* Do not rely on the default parameter if running behind load balancers.
*
* @return boolean True if the IP address belongs to the specified CIDR, false otherwise.
*/
public function ipCIDRcheck(string|array $cidr, ?string $ip = null): bool
{
if ($ip === null) {
$ip = Request::createFromGlobals()->getClientIp() ?? '127.0.0.1';
}
return IpUtils::checkIP($ip, $cidr);
}
}