librenms/scan-snmp.php
Super User ff70062aa9 Initial Import
git-svn-id: http://www.observium.org/svn/observer/trunk@2 61d68cd4-352d-0410-923a-c4978735b2b8
2007-04-03 14:10:23 +00:00

22 lines
609 B
PHP
Executable File

#!/usr/bin/php
<?
include("config.php");
include("includes/functions.php");
$search = $argv[1] . "$";
$data = trim(`cat ips-scanned.txt | grep alive | cut -d" " -f 1 | egrep $search`);
foreach( explode("\n", $data) as $ip) {
$snmp = `snmpget -t 0.1 -v2c -c $community $ip sysName.0`;
if(strstr($snmp, "STRING")) {
$hostname = trim(str_replace("SNMPv2-MIB::sysName.0 = STRING: ","", $snmp));
if(mysql_result(mysql_query("SELECT COUNT(id) FROM devices WHERE hostname = '$hostname'"),0) == '0') {
`./add-host.php $hostname $community v2c`;
echo("Adding $hostname \n");
}
}
}
?>