diff --git a/index.php b/index.php index d22b89e..c61b8e2 100644 --- a/index.php +++ b/index.php @@ -1,128 +1,132 @@ - -

enwiki IPv4 Rangeblock finder

+ +
+

enwiki IPv4 Rangeblock finder

-/> - +
+/> + +
$cookieJar, CURLOPT_COOKIEJAR => $cookieJar, CURLOPT_RETURNTRANSFER => 1, CURLOPT_USERAGENT => 'RangeblockFinder/0.1 (+mailto:wikimedia@stwalkerster.co.uk)', ); const API_ENWIKI = 'https://en.wikipedia.org/w/api.php'; const API_METAWIKI = 'https://meta.wikimedia.org/w/api.php'; function apiQuery($base, array $params, array $substitutions, $post = false) { global $curlOpt; $usableParams = []; foreach ($params as $k => $v) { $val = $v; foreach ($substitutions as $kid => $repl) { $val = str_replace('{' . $kid . '}', $repl, $val); } $usableParams[$k] = $val; } $usableParams['format'] = 'json'; $queryString = http_build_query($usableParams); $url = $base; if (!$post) { $url .= '?' . $queryString; } $ch = curl_init(); curl_setopt_array($ch, $curlOpt); curl_setopt($ch, CURLOPT_URL, $url); if ($post) { curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $queryString); } $data = curl_exec($ch); if (curl_errno($ch)) { die('cURL Error: ' . curl_error($ch)); } return json_decode($data); } function countBlocks($target) { $enwikiGeneralQuery = [ 'action' => 'query', 'list' => 'logevents', 'letitle' => 'User:{0}', 'letype' => 'block', ]; $data = apiQuery(API_ENWIKI, $enwikiGeneralQuery, [$target]); return count($data->query->logevents); } function countGlobalBlocks($target) { $metaGeneralQuery = [ 'action' => 'query', 'list' => 'logevents', 'letitle' => 'User:{0}', 'letype' => 'gblblock', ]; $data = apiQuery(API_METAWIKI, $metaGeneralQuery, [$target]); return count($data->query->logevents); } $ip = filter_var(trim($_POST['ip']), FILTER_VALIDATE_IP); if($ip === false) { die('Not a valid IP!'); } $ipBlocks = countBlocks($ip); $ipGBlocks = countGlobalBlocks($ip); ?> - +
TargetLocal countGlobal count
= 16; --$x) { $mask = -1 << 32 - $x; $val = $ipl & $mask; $range = long2ip($val) . '/' . $x; $ipBlocks = countBlocks($range); $ipGBlocks = countGlobalBlocks($range); ?>
TargetLocal countGlobal count
/32 "> Local log "> Global log
"> Local log "> Global log
+
\ No newline at end of file