File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -375,6 +375,24 @@ analysis purposes. Use the ``anonymize()`` method from the
375
375
$anonymousIpv6 = IpUtils::anonymize($ipv6);
376
376
// $anonymousIpv6 = '2a01:198:603:10::'
377
377
378
+ Check If an IP Belongs to a CIDR Subnet
379
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
380
+
381
+ If you need to know if an IP address is included in a CIDR subnet, you can use
382
+ the ``checkIp() `` method from :class: `Symfony\\ Component\\ HttpFoundation\\ IpUtils `::
383
+
384
+ use Symfony\Component\HttpFoundation\IpUtils;
385
+
386
+ $ipv4 = '192.168.1.56';
387
+ $CIDRv4 = '192.168.1.0/16';
388
+ $isIpInCIDRv4 = IpUtils::checkIp($ipv4, $CIDRv4);
389
+ // $isIpInCIDRv4 = true
390
+
391
+ $ipv6 = '2001:db8:abcd:1234::1';
392
+ $CIDRv6 = '2001:db8:abcd::/48';
393
+ $isIpInCIDRv6 = IpUtils::checkIp($ipv6, $CIDRv6);
394
+ // $isIpInCIDRv6 = true
395
+
378
396
Check if an IP Belongs to a Private Subnet
379
397
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
380
398
You can’t perform that action at this time.
0 commit comments