Issues (2963)

contrib/generate-iplist.php (1 issue)

1
#!/usr/bin/env php
2
<?php
3
4
/*
5
 * LibreNMS
6
 *
7
 *   This file is part of LibreNMS.
8
 *
9
 * @package    LibreNMS
10
 * @subpackage discovery
11
 * @copyright  (C) 2006 - 2012 Adam Armstrong
12
 */
13
14
$init_modules = [];
15
require realpath(__DIR__ . '/..') . '/includes/init.php';
16
17
include_once 'Net/IPv4.php';
18
19
$handle = fopen('ips.txt', 'w');
20
21
foreach (dbFetchRows('SELECT * FROM `ipv4_networks`') as $data) {
22
    $cidr = $data['ipv4_network'];
23
    [$network, $bits] = explode('/', $cidr);
24
    if ($bits != '32' && $bits != '32' && $bits > '22') {
25
        $addr = Net_IPv4::parseAddress($cidr);
0 ignored issues
show
The type Net_IPv4 was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
26
        $broadcast = $addr->broadcast;
27
        $ip = ip2long($network) + 1;
28
        $end = ip2long($broadcast);
29
        while ($ip < $end) {
30
            $ipdotted = long2ip($ip);
31
            if (dbFetchCell('SELECT COUNT(ipv4_address_id) FROM `ipv4_addresses` WHERE `ipv4_address` = ?', [$ipdotted]) == '0' && match_network(\LibreNMS\Config::get('nets'), $ipdotted)) {
32
                fputs($handle, $ipdotted . "\n");
33
            }
34
35
            $ip++;
36
        }
37
    }
38
}
39
40
fclose($handle);
41
42
shell_exec(\LibreNMS\Config::get('fping') . ' -t 100 -f ips.txt > ips-scanned.txt');
43