Last active
September 25, 2024 06:59
-
-
Save technoknol/ec1125b3488f252377b6852be86b191d to your computer and use it in GitHub Desktop.
IP Range CIDR to ALL IP LIST
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// IP Range CIDR to ALL IP LIST | |
// e.g. 220.78.168.0/21 to all IP list Range | |
$start_ip = '220.78.168.0'; | |
$prefix = '28'; | |
$ip_count = 1 << (32 - $prefix); | |
$start = ip2long($start_ip); | |
for ($i = 0; $i < $ip_count; $i++) { | |
echo $ip = long2ip($start + $i) . '<br />'; | |
// do stuff with $ip... | |
} | |
// Output : | |
/* | |
220.78.168.0 | |
220.78.168.1 | |
220.78.168.2 | |
220.78.168.3 | |
220.78.168.4 | |
220.78.168.5 | |
220.78.168.6 | |
220.78.168.7 | |
220.78.168.8 | |
220.78.168.9 | |
220.78.168.10 | |
220.78.168.11 | |
220.78.168.12 | |
220.78.168.13 | |
220.78.168.14 | |
220.78.168.15 | |
*/ | |
// Source: Learn IPv4 Range CIDR | |
// http://aprelium.com/data/doc/2/abyssws-linux-doc-html/ipformat.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Checks if IP is in Given IP CIDR range or not.
Another logic
NOT TESTED FULLY YET