Created
July 31, 2014 23:18
-
-
Save TimWolla/d6cfba2839b0d2fd23e0 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
#!/usr/bin/env php | |
<?php | |
if ($argc !== 2) { | |
echo "Usage: ".$argv[0]." 127.0.0.1/8"; | |
exit; | |
} | |
list($ip, $net) = explode('/', $argv[1]); | |
if ($net > 32 || $net < 0) exit; | |
$long = ip2long($ip); | |
$size = $net; | |
$long = $long & ~((1 << (32 - $size)) - 1); | |
for ($start = $long; ($long & ~((1 << (32 - $size)) - 1)) == ($start & ~((1 << (32 - $size)) - 1)); $long++) { | |
echo long2ip($long)."\n"; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment