2010-09-03 18:26:59 +00:00
#!/usr/bin/env php
2009-09-07 11:07:59 +00:00
< ? php
2015-07-13 20:10:26 +02:00
/*
2016-09-08 14:12:23 +01:00
* LibreNMS
2012-05-09 10:01:42 +00:00
*
2016-09-08 14:12:23 +01:00
* This file is part of LibreNMS .
2012-05-09 10:01:42 +00:00
*
2016-09-08 14:12:23 +01:00
* @ package LibreNMS
2013-10-28 12:01:36 -07:00
* @ subpackage discovery
* @ copyright ( C ) 2006 - 2012 Adam Armstrong
2012-05-09 10:01:42 +00:00
*/
2016-11-21 14:12:59 -06:00
$init_modules = array ();
require realpath ( __DIR__ . '/..' ) . '/includes/init.php' ;
2015-07-13 20:10:26 +02:00
2017-08-08 14:14:58 -05:00
include_once 'Net/IPv4.php' ;
2015-07-13 20:10:26 +02:00
$handle = fopen ( 'ips.txt' , 'w' );
2007-04-03 14:10:23 +00:00
2015-07-13 20:10:26 +02:00
foreach ( dbFetchRows ( 'SELECT * FROM `ipv4_networks`' ) as $data ) {
$cidr = $data [ 'ipv4_network' ];
list ( $network , $bits ) = explode ( '/' , $cidr );
if ( $bits != '32' && $bits != '32' && $bits > '22' ) {
$addr = Net_IPv4 :: parseAddress ( $cidr );
$broadcast = $addr -> broadcast ;
2017-08-08 14:14:58 -05:00
$ip = ip2long ( $network ) + 1 ;
2015-07-13 20:10:26 +02:00
$end = ip2long ( $broadcast );
while ( $ip < $end ) {
$ipdotted = long2ip ( $ip );
if ( dbFetchCell ( 'SELECT COUNT(ipv4_address_id) FROM `ipv4_addresses` WHERE `ipv4_address` = ?' , array ( $ipdotted )) == '0' && match_network ( $config [ 'nets' ], $ipdotted )) {
fputs ( $handle , $ipdotted . " \n " );
}
2007-04-03 14:10:23 +00:00
2015-07-13 20:10:26 +02:00
$ip ++ ;
}
2007-04-03 14:10:23 +00:00
}
}
2011-03-08 18:17:49 +00:00
fclose ( $handle );
2016-11-21 14:12:59 -06:00
shell_exec ( $config [ 'fping' ] . ' -t 100 -f ips.txt > ips-scanned.txt' );