function process_file($path, $folder) { global $g_total, $g_good, $g_poor, $g_neutral; $fh = fopen($path, "rb"); if (!$fh) { return; } //$fp = fsockopen("192.168.1.233", 19990); $output = ''; $line = ''; //$line = fgets($fh); // skip first line (headers) $n_total = 0; $n_good = 0; $n_poor = 0; $n_neutral = 0; while (($line = fgets($fh)) !== false) { ++$n_total; $t = explode(",", $line); $ip = trim($t[0]); $sbrs = trim($t[6]); if (strcasecmp($sbrs, "Good") == 0) { $output .= ip_to_5byte($ip, 0xff); ++$n_good; } else { if (strcasecmp($sbrs, "Poor") == 0) { $output .= ip_to_5byte($ip, 0x0); ++$n_poor; } else { if (strcasecmp($sbrs, "Neutral") == 0) { $output .= ip_to_5byte($ip, 0xf0); ++$n_neutral; //$score = ask_srl($fp, $ip); //$output .= "$ip\t$score\n"; } else { //echo "$ip:$sbrs\n"; } } } } //fclose($fp); fclose($fh); file_put_contents("{$folder}.ips", $output, FILE_APPEND); // FILE_APPEND echo "good/neutral/poor/total={$n_good}/{$n_neutral}/{$n_poor}/{$n_total}\n"; $n_diff = $n_total - $n_good - $n_neutral - $n_poor; echo "check sum: {$n_diff}\n"; $g_total += $n_total; $g_good += $n_good; $g_neutral += $n_neutral; $g_poor += $n_poor; }
file_put_contents($ips_file, $output); $count = -1; while (!feof($fh)) { $line = fgets($fh); if ($count < 0) { if (strncmp($line, "127.0.0.", strlen("127.0.0.")) == 0) { ++$count; } continue; } $ip = trim($line); if ($ip == '') { continue; } //echo "$ip\n"; $output .= ip_to_5byte($ip, 0x0); // always Poor IP ++$count; if (strlen($output) >= 200 * 1024) { file_put_contents($ips_file, $output, FILE_APPEND); echo '.'; $output = ''; } } file_put_contents($ips_file, $output, FILE_APPEND); echo '.'; fclose($fh); echo "\n{$ips_file} created! (count:{$count})\n"; function ip_to_5byte($ip, $flag) { $octet = '';