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 @@ -362,6 +362,24 @@ analysis purposes. Use the ``anonymize()`` method from the
362
362
$anonymousIpv6 = IpUtils::anonymize($ipv6);
363
363
// $anonymousIpv6 = '2a01:198:603:10::'
364
364
365
+ Check If an IP Belongs to a CIDR Subnet
366
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
367
+
368
+ If you need to know if an IP address is included in a CIDR subnet, you can use
369
+ the ``checkIp() `` method from :class: `Symfony\\ Component\\ HttpFoundation\\ IpUtils `::
370
+
371
+ use Symfony\Component\HttpFoundation\IpUtils;
372
+
373
+ $ipv4 = '192.168.1.56';
374
+ $CIDRv4 = '192.168.1.0/16';
375
+ $isIpInCIDRv4 = IpUtils::checkIp($ipv4, $CIDRv4);
376
+ // $isIpInCIDRv4 = true
377
+
378
+ $ipv6 = '2001:db8:abcd:1234::1';
379
+ $CIDRv6 = '2001:db8:abcd::/48';
380
+ $isIpInCIDRv6 = IpUtils::checkIp($ipv6, $CIDRv6);
381
+ // $isIpInCIDRv6 = true
382
+
365
383
Check if an IP Belongs to a Private Subnet
366
384
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
367
385
You can’t perform that action at this time.
0 commit comments