Add -a to arp, add ZM_PATH_OUI for path to ieee-oui.txt

openbsd
Charlie Root 2023-09-13 10:14:49 -07:00
parent c4302c27ac
commit fccebee056
1 changed files with 19 additions and 15 deletions

View File

@ -694,12 +694,12 @@ function get_arp_results() {
return $results;
}
if (count($result)==1) {
$arp_command .= ' -n';
$arp_command .= ' -an';
}
$result = exec(escapeshellcmd($arp_command), $output, $status);
if ($status) {
ZM\Error("Unable to probe network cameras, status is '$status'");
ZM\Error("Unable to probe network cameras using $arp_command, status is '$status' output is ".implode("\n", $output));
return $results;
}
foreach ($output as $line) {
@ -779,21 +779,25 @@ function probeNetwork() {
ZM\Warning('No content from '.ZM_PATH_DATA.'/MacVendors.json');
}
$macBases = json_decode($macVendors, true);
$oui_txt = file_get_contents('/usr/share/arp-scan/ieee-oui.txt');
if (!$oui_txt) {
ZM\Warning('No content from /usr/share/arp-scan/ieee-oui.txt');
} else {
foreach (explode(PHP_EOL, $oui_txt) as $line) {
if (false === strpos($line , '#')) {
$record = explode("\t", $line);
if (count($record) < 2) continue;
$mac = strtolower($record[0]);
$type = preg_replace('/\W/', '', $record[1]);
if (!isset($macBases[$mac]))
$macBases[$mac] = [ 'vendor'=>$record[1], 'type'=>$type];
if (defined('ZM_PATH_OUI') and ZM_PATH_OUI and file_exists(ZM_PATH_OUI)) {
$oui_txt = file_get_contents(ZM_PATH_OUI);
if (!$oui_txt) {
ZM\Warning('No content from /usr/share/arp-scan/ieee-oui.txt');
} else {
foreach (explode(PHP_EOL, $oui_txt) as $line) {
if (false === strpos($line , '#')) {
$record = explode("\t", $line);
if (count($record) < 2) continue;
$mac = strtolower($record[0]);
$type = preg_replace('/\W/', '', $record[1]);
if (!isset($macBases[$mac]))
$macBases[$mac] = [ 'vendor'=>$record[1], 'type'=>$type];
}
}
#ZM\Debug("bases: " . print_r($macBases, true));
}
#ZM\Debug("bases: " . print_r($macBases, true));
} else {
ZM\Debug("No ieee-oui.txt");
}
foreach (get_arp_results() as $mac=>$ip) {