Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion functions/classes/class.phpipamAgent.php
Original file line number Diff line number Diff line change
Expand Up @@ -1027,10 +1027,43 @@ private function mysql_scan_discovered_write_to_db ($subnets) {
unset($this->Database);
$this->Database = new Database_PDO ();
}
// Try to load kernel ARP table into an array
$arp = [];
$arpFile = "/proc/net/arp";
if (file_exists($arpFile)) {
if ($handle = fopen($arpFile, "r")) {
// Skip the header line
fgets($handle);
// Loop through each line
while (($line = fgets($handle)) !== false) {
if (sscanf($line, "%s %*s %*s %s %*s %s", $ip, $mac, $int) === 6) {
// Proc ARP table includes blank values for hosts that did not respond, filter those out
if ($mac !== "00:00:00:00:00:00") {
$arp["$ip"] = [
"mac" => $mac,
"int" => $int
];
}
}
}
fclose($handle);
}
}
// loop
foreach($subnets as $s) {
if (isset($s->discovered) && is_array($s->discovered)) {
foreach($s->discovered as $ip) {
// Check kernel arp table array for a matching entry
// Move note text processing here so we can add the interface
$note = "This host was autodiscovered on ".$this->nowdate. " by agent ".$this->agent_details->name;
// If we have discovered a MAC address, add it and append to the note identifying the interface
if (array_key_exists($ip, $arp)) {
$mac = $this->reformat_mac_address ($arp["$ip"]["mac"]);
$note .= " on interface ".$arp["$ip"]["int"];
} else {
// Define an empty MAC so DB insert does not error if no match
$mac = null;
}
// try to resolve hostname
$tmp = new stdClass();
$tmp->ip_addr = $ip;
Expand All @@ -1039,8 +1072,9 @@ private function mysql_scan_discovered_write_to_db ($subnets) {
$values = array("subnetId"=>$s->id,
"ip_addr"=>$this->transform_address($ip, "decimal"),
"hostname"=>$hostname['name'],
"mac"=>$mac,
"description"=>"-- autodiscovered --",
"note"=>"This host was autodiscovered on ".$this->nowdate. " by agent ".$this->agent_details->name,
"note"=>$note,
"lastSeen"=>$this->nowdate,
"state"=>"2"
);
Expand Down