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
362362 $anonymousIpv6 = IpUtils::anonymize($ipv6);
363363 // $anonymousIpv6 = '2a01:198:603:10::'
364364
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+
365383Check if an IP Belongs to a Private Subnet
366384~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
367385
You can’t perform that action at this time.
0 commit comments