<?php
$now = date("m/j/y h:i:s",time());
include "connect.php";
$stmt = "Select * FROM switches where (switch_type='FOUNDRY');";
$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");
$interfacetable = snmpwalk($row->IP_ADDRESS, "$row->SNMPSTRING",".1.3.6.1.2.1.2.2.1.2");
$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>";
$thisportnum = explode(".", $interface[$i]);
$portnum = $thisportnum[4];
$macaddress2 = explode(".", $macaddress[$i]);
list ($ip4, $mac) = split("= ", $macaddress2[8]);
$ip = $macaddress2[5] . '.' . $macaddress2[6] . '.' . $macaddress2[7] . '.' . $ip4;
$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];
}
}
print "<td>" . $mymac . "</td>";
$thisportdesc = "None";
for ($j=0; $j<count($interfacetable); $j++) {
$thisinterface = explode(".", $interfacetable[$j]);
list ($thisportnumber, $thisportname) = split("= ", $thisinterface[4]);
// print $thisportnum;
if (trim($thisportnumber) == trim($portnum)) {
$thisportdesc=$thisportname;
}
}
print "<td>" . $thisportdesc . "</td>";
// print "<td>" . $interfacetable[$i] . "</td>";
if (($mymac != 'ffffffffffff') && ($mymac != ''))
{
$stmt3 = "update arp_table set switch = '$host', switch_port = '$thisportdesc' where mac_address = '$mymac';";
$sth3 = ibase_query($dbh, $stmt3);
}
print "</tr>";
}
print "</table>";
}
ibase_free_result($sth);
ibase_close($dbh);
?>