<head>
<title>NAMA Arp</title>
</head>
<?php
$now = date("m/j/y h:i:s",time());
include "connect.php";
$stmt = "Select * FROM routers;";
$sth = ibase_query($dbh, $stmt);
while ($row = ibase_fetch_object($sth)) {
$interface = snmpwalk($row->IP_ADDRESS, "$row->SNMPSTRING",".1.3.6.1.2.1.4.22.1.1");
$macaddress = snmpwalk($row->IP_ADDRESS, "$row->SNMPSTRING",".1.3.6.1.2.1.4.22.1.2");
$ipaddress = snmpwalk($row->IP_ADDRESS, "$row->SNMPSTRING",".1.3.6.1.2.1.4.22.1.3");
$now = date("m/j/y h:i:s",time());
$host = $row->IP_ADDRESS;
$community = "$row->SNMPSTRING";
$sysDescr = snmpget("$host","$community","system.sysDescr.0");
# print '<META HTTP-EQUIV="refresh" CONTENT="600">';
print '<body bgcolor="#FFFFCC" text="#000000">';
echo $now . "<br>";
print "<table border=1 bgcolor=#ffffcc><tr><td>$host</td></tr></table>
";
print "<table border=1 bgcolor=#ffffcc><tr><td>$sysDescr</td></tr></table>
";
print "<table border=1 bgcolor=#ffffcc>";
print "<tr>
<td>ifIndex</td>
<td>IP Address</td>
<td>MAC Address</td>
<td>IP Integer</td>
</tr>";
for ($i=0; $i<count($macaddress); $i++) {
print "<tr>";
print "<td>$interface[$i]</td>";
list($junk, $mac) = split("STRING: ", $macaddress[$i]);
list($junk, $ip) = split("IpAddress: ", $ipaddress[$i]);
$ip2 = explode(".", $ip);
$subnet = $ip2[0] . "." . $ip2[1] . "." . $ip2[2] . ".0";
print "<td>$ip</td>";
$mac = split(":",$mac);
$mymac = "";
for ($j=0; $j<count($mac); $j++) {
if (strlen($mac[$j]) == 1) {
$mymac = $mymac . "0" . $mac[$j];
} else {
$mymac = $mymac . $mac[$j];
}
}
$liasostmt="select o.email_address, o.first_name, o.last_name, o.phone from subnets s, lab l, owner o where (s.subnet='" . $subnet . "') and (s.lab=l.serial) and (l.liaso=o.serial)";
$liasoqry = ibase_query($dbh, $liasostmt);
$liasorow = ibase_fetch_object($liasoqry);
$liaso=$liasorow->EMAIL_ADDRESS;
$liasoname=$liasorow->FIRST_NAME . ' ' . $liasorow->LAST_NAME;
$liasophone = $liasorow->PHONE;
print "<td>$mymac</td>";
print "<td>";
printf("%u",ip2long($ip));
$iplong = ip2long($ip);
print "</td>";
if (($ip!='192.168.0.1') || //add any addresses you don't want to monitor here.
($subnet!='224.0.0') ||
($ip!='127.0.0.1')) {
if (($mymac != 'ffffffffffff') && ($mymac != '')) {
$stmtzero = "update arp_table set ip_address = '0.0.0.0' where (ip_address = '$ip') and (lower(MAC_ADDRESS) <> '$mymac');";
$stmtzero = ibase_query($dbh, $stmtzero);
$stmt2 = "select SERIAL, IP_ADDRESS, SUBNET, MULTINICK, SENT_EMAIL, LAST_SEEN, MD5 from ARP_TABLE where lower(MAC_ADDRESS) = '$mymac';";
$sth2 = ibase_query($dbh, $stmt2);
if ($row2 = ibase_fetch_object($sth2)) {
print "<td>Found " . $row2->IP_ADDRESS . '->' . $ip;
if ($row2->MULTINICK == '1') {
print " <b>Multinick</b>";
}
print "</td>";
if ($row2->IP_ADDRESS != $ip) {
$nip = explode(".", $ip);
$newsubnet = $nip[0] . "." . $nip[1] . "." . $nip[2] . ".0";
if ($row2->SUBNET != $newsubnet) {
$stmt3 = "update arp_table set IP_ADDRESS = '$ip', SUBNET = '$newsubnet', LAST_SEEN = '$now', IPNUM = '$iplong', SENT_EMAIL = '$now' where SERIAL = '$row2->SERIAL';";
} else {
$stmt3 = "update arp_table set IP_ADDRESS = '$ip', SUBNET = '$newsubnet', LAST_SEEN = '$now', IPNUM = '$iplong' where SERIAL = '$row2->SERIAL';";
}
$sth3 = ibase_query($dbh, $stmt3);
// $stmt5 = "update machine_table set IP = '$ip' where IP = '$row2->IP_ADDRESS'";
// $sth5 = ibase_query($dbh, $stmt5);
if ($row2->SUBNET != $newsubnet) {
if ((strtotime($now)-strtotime($row2->LAST_SEEN))>75000) {
if ($row2->SENT_EMAIL == '') {
$mymd5 = $row2->MD5;
include "mailmoved.inc";
}
}
}
} else {
$stmt3 = "update arp_table set LAST_SEEN = '$now' where SERIAL = '$row2->SERIAL';";
$sth3 = ibase_query($dbh, $stmt3);
}
} else {
print "<td>Not Found</td>";
$mymd5 = md5($now);
$stmt3 = "insert into arp_table (MAC_ADDRESS, IP_ADDRESS, FIRST_SEEN, LAST_SEEN, IPNUM, SUBNET, MD5) VALUES ('$mymac', '$ip', '$now', '$now', '$iplong', '$subnet', '$mymd5');";
echo $stmt3 . '<br>';
if (($liasoname != '') && ($liasophone != '')) {
include "mailnew.inc";
$sth3 = ibase_query($dbh, $stmt3);
$popupmsg = 'This system has not been accredited for Network use. Please register the system with the NAMA Database. For assistance contact your LIASO, ' . $liasoname . ' at ' . $liasophone . '.';
// $execit = "/usr/bin/netsend $ip $popupmsg >> data/test 2>&1";
// exec($execit);
}
}
print "</tr>";
ibase_free_result($sth2);
}
}
}
print "</table>";
}
ibase_free_result($sth);
ibase_close($dbh);
?>