#!/usr/bin/php &$xxx) { $country = strtolower($country); $xxx = ipv4_merge_address_blocks($xxx, "$country: Step 2 - "); // --- CIDR finden --- echo "$country: Step 3 - Analyze address ranges and write CIDR blocks\n"; $hf = fopen(DIR . "/out/ipv4_{$country}_cidr.new", 'w'); $hs = fopen(DIR . "/out/ipv4_{$country}_cidr_shortened.new", 'w'); $hb = fopen(DIR . "/out/ipv4_{$country}_blocks.new", 'w'); foreach ($xxx as $baseip => &$topip) { fwrite($hb, ipv4_complete($baseip)." - ".ipv4_complete($topip)."\n"); $rirstat_file = ipv4_range2cidr($baseip, $topip, true); foreach ($rirstat_file as $x) { fwrite($hs, "$x\n"); } $rirstat_file = ipv4_range2cidr($baseip, $topip, false); foreach ($rirstat_file as $x) { fwrite($hf, "$x\n"); } } fclose($hb); fclose($hs); fclose($hf); rename(DIR . "/out/ipv4_{$country}_cidr.new", DIR . "/out/ipv4_{$country}_cidr"); rename(DIR . "/out/ipv4_{$country}_cidr_shortened.new", DIR . "/out/ipv4_{$country}_cidr_shortened"); rename(DIR . "/out/ipv4_{$country}_blocks.new", DIR . "/out/ipv4_{$country}_blocks"); $written_files[] = DIR . "/out/ipv4_{$country}_cidr"; $written_files[] = DIR . "/out/ipv4_{$country}_cidr_shortened"; $written_files[] = DIR . "/out/ipv4_{$country}_blocks"; } $all_files = glob(DIR . "/out/ipv4_*"); foreach ($all_files as $file) { if (!in_array($file, $written_files)) { unlink($file); echo "Deleted because not touched: $file\n"; } } echo "Finished!\n";