Here's a quick function I wrote to generate IP address ranges using recursion.
function iprange($oct, $prefix=""){
for($i=1;$i<256;$i++){
if($oct == 1) print("$prefix.$i\\n");
else iprange($oct - 1, "$prefix.$i");
}
}
Just call it with the number of octets you want to generate and the beginning of the IP range.
Example:
iprange(2, "127.0");
Output:
127.0.1.1
127.0.1.2
127.0.1.3
127.0.1.4
127.0.1.5
…
127.0.255.254
127.0.255.255
Enjoy ![]()