Last active
July 15, 2016 10:38
-
-
Save Fedcomp/cae5ad9e3839f9eee790e229ef265d23 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 | |
$filename = "ip.list"; | |
$prefix = "2a04:5200:8"; | |
$ips_amount = null; | |
if(isset($argv[1])){ | |
$ips_amount = (int) $argv[1]; | |
} else { | |
$ips_amount = 1; | |
} | |
function generate_ipv6_block() { | |
$seed = str_split('1234567890abcdef'); | |
shuffle($seed); | |
$block = join("", $seed); // Symbol array to string | |
$block = substr($block, 0, 4); | |
return $block; | |
} | |
function generate_ipv6($prefix){ | |
$a = generate_ipv6_block(); | |
$b = generate_ipv6_block(); | |
$c = generate_ipv6_block(); | |
$d = generate_ipv6_block(); | |
$e = generate_ipv6_block(); | |
return "{$prefix}:{$a}:{$b}:{$c}:{$d}:{$e}"; | |
} | |
function generate_unique_ipv6($prefix, $iplist) { | |
$ipv6 = null; // Scope | |
do { | |
$ipv6 = generate_ipv6($prefix); | |
} while(in_array($ipv6, $iplist)); | |
return $ipv6; | |
} | |
if(file_exists($filename)){ | |
$ips = trim(file_get_contents($filename)); | |
$ips = explode("\n", $ips); | |
} | |
else{ | |
$ips = []; | |
} | |
for($i = 0; $i < $ips_amount; $i++){ | |
$ip = generate_unique_ipv6($prefix, $ips); | |
$ips[] = $ip; | |
echo $ip . "\n"; | |
} | |
file_put_contents($filename, implode("\n", $ips)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment