');
$query = "SELECT * FROM `ipv4_mac` AS M, `ports` AS P, `devices` AS D WHERE M.port_id = P.port_id AND P.device_id = D.device_id ";
if (isset($_POST['searchby']) && $_POST['searchby'] == "ip")
{
$query .= " AND `ipv4_address` LIKE ?";
$param = array("%".trim($_POST['address'])."%");
} else {
$query .= " AND `mac_address` LIKE ?";
$param = array("%".str_replace(array(':', ' ', '-', '.', '0x'),'',mres($_POST['address']))."%");
}
if (is_numeric($_POST['device_id']))
{
$query .= " AND P.device_id = ?";
$param[] = $_POST['device_id'];
}
$query .= " ORDER BY M.mac_address";
echo('MAC Address | IP Address | Device | Interface | Remote device | Remote interface |
');
foreach (dbFetchRows($query, $param) as $entry)
{
if (!$ignore)
{
//why are they here for?
//$speed = humanspeed($entry['ifSpeed']);
//$type = humanmedia($entry['ifType']);
if ($entry['ifInErrors'] > 0 || $entry['ifOutErrors'] > 0)
{
$error_img = generate_port_link($entry,"
",errors);
} else { $error_img = ""; }
$arp_host = dbFetchRow("SELECT * FROM ipv4_addresses AS A, ports AS I, devices AS D WHERE A.ipv4_address = ? AND I.port_id = A.port_id AND D.device_id = I.device_id", array($entry['ipv4_address']));
if ($arp_host) { $arp_name = generate_device_link($arp_host); } else { unset($arp_name); }
if ($arp_host) { $arp_if = generate_port_link($arp_host); } else { unset($arp_if); }
if ($arp_host['device_id'] == $entry['device_id']) { $arp_name = "Localhost"; }
if ($arp_host['port_id'] == $entry['port_id']) { $arp_if = "Local port"; }
echo('
' . formatMac($entry['mac_address']) . ' |
' . $entry['ipv4_address'] . ' |
' . generate_device_link($entry) . ' |
' . generate_port_link($entry, makeshortif(fixifname($entry['ifDescr']))) . ' ' . $error_img . ' |
'.$arp_name.' |
'.$arp_if.' |
');
}
unset($ignore);
}
echo("");
?>