<?php// this script comes "as is"// use it at your own risk$cacheDirectory = "/var/cache/scraper/";$cacheMaxAge = 60; // in seconds// no changes should be necessary below thiserror_reporting(0);header("Content-Type: text/plain");if (!is_dir($cacheDirectory)) { if (!mkdir($cacheDirectory, 777, true)) { echo "# could not create cache directory"; exit; }}if (!@filter_var($_GET["url"], FILTER_VALIDATE_URL)) { echo "# invalid url"; exit;}$currentTime = time();$currentDate = date(DATE_RFC2822);$cachePath6 = $cacheDirectory . "/" . md5($_GET["url"]);$cachePath4 = $cachePath6 . ".IPv4.txt";$cachePath6 = $cachePath6 . ".IPv6.txt";$cacheOldAge6 = false;if (!@$_GET["v"] || $_GET["v"] == 6) { $cacheOldAge6 = $currentTime - filectime($cachePath6) > $cacheMaxAge;}$cacheOldAge4 = false;if (!@$_GET["v"] || $_GET["v"] == 4) { $cacheOldAge4 = $currentTime - filectime($cachePath4) > $cacheMaxAge;}if ($cacheOldAge6 || $cacheOldAge4) { $curlHandle = curl_init(); curl_setopt($curlHandle, CURLOPT_URL, urldecode($_GET["url"])); curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true); curl_setopt($curlHandle, CURLOPT_HEADER, false); curl_setopt($curlHandle, CURLOPT_TIMEOUT, 10); curl_setopt($curlHandle, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:121.0) Gecko/20100101 Firefox/115.0"); $response = curl_exec($curlHandle); $httpCode = curl_getinfo($curlHandle, CURLINFO_HTTP_CODE); curl_close($curlHandle); if ($response !== false && $httpCode == 200) { $response = trim(preg_replace("/(?:[\#;]|\/{2}).*/", "", $response)); if (preg_match_all("/((?:[\da-f]{0,4}:){2,7}(?:(?:(?:(?:25[0-5]|2[0-4]\d|1?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|1?\d\d?))|[\da-f]{0,4}|:))(?:\/(12[0-8]|1[01][0-9]|[1-9]?[0-9]))?/", $response, $matches)) { file_put_contents($cachePath6, "# {$currentDate} - IPv6\n" . implode("\n", array_map(function ($a, $b) { if (filter_var($a, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { return "{$a}/" . ($b ? $b : "128"); } }, $matches[1], $matches[2]))); } else { @unlink($cachePath6); } if (preg_match_all("/((?:(?:25[0-5]|2[0-4]\d|1?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|1?\d\d?))(?:\/(3[0-2]|[12]?[0-9]))?/", $response, $matches)) { file_put_contents($cachePath4, "# {$currentDate} - IPv4\n" . implode("\n", array_map(function ($a, $b) { if (filter_var($a, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { return "{$a}/" . ($b ? $b : "32"); } }, $matches[1], $matches[2]))); } else { @unlink($cachePath4); } }}if (!@$_GET["v"] || $_GET["v"] == 6) { echo @file_get_contents($cachePath6);}if (!@$_GET["v"] || $_GET["v"] == 4) { echo @file_get_contents($cachePath4);}