Last active
August 29, 2015 14:05
-
-
Save Dragory/d5671d6887b9c70348d5 to your computer and use it in GitHub Desktop.
This file contains 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 | |
$startIP = [1, 1, 1, 50]; | |
$numToGenerate = 255; | |
// Convert the array into the binary representation | |
$startIP = array_map(function($num) { | |
return str_pad(decbin($num), 8, "0", STR_PAD_LEFT); | |
}, $startIP); | |
$startIP = implode('', $startIP); // Should be 32 bits represented as binary here (in a string) | |
// Generate the IPs | |
$startIPDec = bindec($startIP); | |
$results = []; | |
for ($i = 0; $i < $numToGenerate; $i++) { | |
// Save each IP as the 32 bit binary string | |
$results[] = str_pad(decbin($startIPDec + $i), 32, "0", STR_PAD_LEFT); | |
} | |
// Output | |
foreach ($results as $result) { | |
echo implode('.', array_map('bindec', str_split($result, 8))); | |
echo '<br>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment