diff --git a/LICENCE b/LICENCE new file mode 100644 index 0000000..6981df8 --- /dev/null +++ b/LICENCE @@ -0,0 +1,13 @@ +Copyright 2020 Simon Walker (and others) + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the Software without restriction, including without limitation the +rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit +persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/composer.json b/composer.json index 6df43fe..4c156d3 100644 --- a/composer.json +++ b/composer.json @@ -1,14 +1,14 @@ { "authors": [ { "name": "Simon Walker", "email": "github@stwalkerster.co.uk" } ], "require": { "ext-json": "*", "ext-curl": "*", - "twbs/bootstrap": "v4.3.1", + "twbs/bootstrap": "v4.*", "mlocati/ip-lib": "1.*" } } diff --git a/composer.lock b/composer.lock index 2301beb..8983481 100644 --- a/composer.lock +++ b/composer.lock @@ -1,128 +1,130 @@ { "_readme": [ "This file locks the dependencies of your project to a known state", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "014c4600270f10a859034b247a73f07f", + "content-hash": "0e647c1f50e5a15b1b452b07b295fa7e", "packages": [ { "name": "mlocati/ip-lib", - "version": "1.9.0", + "version": "1.13.0", "source": { "type": "git", "url": "https://github.com/mlocati/ip-lib.git", - "reference": "b844659e3b87a461d1a8fe8e3e374aa6c4a5d902" + "reference": "334de586c7894afd838be44d73e72d8e97e5b0ff" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/mlocati/ip-lib/zipball/b844659e3b87a461d1a8fe8e3e374aa6c4a5d902", - "reference": "b844659e3b87a461d1a8fe8e3e374aa6c4a5d902", + "url": "https://api.github.com/repos/mlocati/ip-lib/zipball/334de586c7894afd838be44d73e72d8e97e5b0ff", + "reference": "334de586c7894afd838be44d73e72d8e97e5b0ff", "shasum": "" }, "require": { "php": ">=5.3.3" }, "require-dev": { "ext-pdo_sqlite": "*", "phpunit/dbunit": "^1.4 || ^2 || ^3 || ^4", "phpunit/phpunit": "^4.8 || ^5.7 || ^6.5" }, "type": "library", "autoload": { "psr-4": { "IPLib\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], "authors": [ { "name": "Michele Locati", "email": "mlocati@gmail.com", "homepage": "https://github.com/mlocati", "role": "Author" } ], "description": "Handle IPv4, IPv6 addresses and ranges", "homepage": "https://github.com/mlocati/ip-lib", "keywords": [ "IP", "address", "addresses", "ipv4", "ipv6", + "manage", + "managing", "matching", "network", "networking", "range", "subnet" ], - "time": "2019-09-20T08:26:10+00:00" + "time": "2020-10-04T12:22:58+00:00" }, { "name": "twbs/bootstrap", - "version": "v4.3.1", + "version": "v4.5.3", "source": { "type": "git", "url": "https://github.com/twbs/bootstrap.git", - "reference": "8fa0d3010112dca5dd6dd501173415856001ba8b" + "reference": "a716fb03f965dc0846df479e14388b1b4b93d7ce" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twbs/bootstrap/zipball/8fa0d3010112dca5dd6dd501173415856001ba8b", - "reference": "8fa0d3010112dca5dd6dd501173415856001ba8b", + "url": "https://api.github.com/repos/twbs/bootstrap/zipball/a716fb03f965dc0846df479e14388b1b4b93d7ce", + "reference": "a716fb03f965dc0846df479e14388b1b4b93d7ce", "shasum": "" }, "replace": { "twitter/bootstrap": "self.version" }, "type": "library", "extra": { "branch-alias": { "dev-master": "3.3.x-dev" } }, "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], "authors": [ - { - "name": "Jacob Thornton", - "email": "jacobthornton@gmail.com" - }, { "name": "Mark Otto", "email": "markdotto@gmail.com" + }, + { + "name": "Jacob Thornton", + "email": "jacobthornton@gmail.com" } ], "description": "The most popular front-end framework for developing responsive, mobile first projects on the web.", "homepage": "https://getbootstrap.com/", "keywords": [ "JS", "css", "framework", "front-end", "mobile-first", "responsive", "sass", "web" ], - "time": "2019-02-13T16:01:40+00:00" + "time": "2020-10-13T15:38:30+00:00" } ], "packages-dev": [], "aliases": [], "minimum-stability": "stable", "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, "platform": { "ext-json": "*", "ext-curl": "*" }, "platform-dev": [] } diff --git a/index.php b/index.php index ac03964..ff07959 100644 --- a/index.php +++ b/index.php @@ -1,190 +1,227 @@ - + - + Rangeblock finder - -
-

Rangeblock finder

-
-
- /> - -
-
+ +
+
+

Rangeblock finder

+
+
+
+ + /> +
+
+ +
+
+
+
+
+
+ > + +
+
+
+
+
+
+ + + + "; + writeFooter(); die(); } $cookieJar = tempnam("/tmp", "CURLCOOKIE"); $curlOpt = array( CURLOPT_COOKIEFILE => $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($_REQUEST['ip']), FILTER_VALIDATE_IP); -//if($ip === false) { -// echo '
Not a valid IP!
'; -// echo "
"; -// die(); -//} - $address = Factory::addressFromString($_REQUEST['ip']); - +$excludeLowV6 = isset($_REQUEST['excludelow']); $ipBlocks = countBlocks($address->toString()); $ipGBlocks = countGlobalBlocks($address->toString()); ?> getAddressType() == Type::T_IPv4) { /** @var IPv4 $v4Address */ $v4Address = $address; for($x = 32; $x >= 16; --$x) { $range = Subnet::fromString($v4Address->toString() . "/${x}"); $ipBlocks = countBlocks($range); $ipGBlocks = countGlobalBlocks($range); writeTableRow($x, $range->getStartAddress(), $range->getEndAddress(), $ipBlocks, $ipGBlocks); } } else if($address->getAddressType() == Type::T_IPv6) { /** @var IPv6 $v6Address */ $v6Address = $address; - for($x = 128; $x >= 19; --$x) { + global $excludeLowV6; + $lowerBound = 128; + + if($excludeLowV6) { + $lowerBound = 64; + + // manually re-add 128. + $range = Subnet::fromString($v6Address->toString() . "/128"); + $ipBlocks = countBlocks($range); + $ipGBlocks = countGlobalBlocks($range); + + writeTableRow(128, $range->getStartAddress(), $range->getEndAddress(), $ipBlocks, $ipGBlocks); + + ?> + + = 19; --$x) { $range = Subnet::fromString($v6Address->toString() . "/${x}"); $ipBlocks = countBlocks($range); $ipGBlocks = countGlobalBlocks($range); writeTableRow($x, $range->getStartAddress(), $range->getEndAddress(), $ipBlocks, $ipGBlocks); } } ?>
TargetCIDRUpper bound of rangeLocal block countGlobal block count
toString() ?> "> Local log "> Global log
/ "> ">Local log "> ">Global log
Checking low CIDR prefixes skipped. To re-run the check for all CIDR prefixes, click here
- - - +