File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -353,6 +353,27 @@ analysis purposes. Use the ``anonymize()`` method from the
353
353
$anonymousIpv6 = IpUtils::anonymize($ipv6);
354
354
// $anonymousIpv6 = '2a01:198:603:10::'
355
355
356
+
357
+ Check if an IP belongs to a CIDR subnet
358
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
359
+
360
+ If you need to know if an IP address is included in a CIDR subnet, you can
361
+ use the ``checkIp `` method from the
362
+ :class: `Symfony\\ Component\\ HttpFoundation\\ IpUtils ` to do that::
363
+
364
+ use Symfony\Component\HttpFoundation\IpUtils;
365
+
366
+ $ipv4 = '192.168.1.56';
367
+ $CIDRv4 = '192.168.1.0/16';
368
+ $isIpInCIDRv4 = IpUtils::checkIp($ipv4, $CIDRv4);
369
+ // $isIpInCIDRv4 = true
370
+
371
+ $ipv6 = '2001:db8:abcd:1234::1';
372
+ $CIDRv6 = '2001:db8:abcd::/48';
373
+ $isIpInCIDRv6 = IpUtils::checkIp($ipv6, $CIDRv6);
374
+ // $isIpInCIDRv6 = true
375
+
376
+
356
377
Accessing other Data
357
378
~~~~~~~~~~~~~~~~~~~~
358
379
You can’t perform that action at this time.
0 commit comments