Location: PHPKode > projects > Network Asset Management Archive > nama/arpfile.php
<head>
<title>Arp file</title>
</head>
<?php
$now = date("m/j/y h:i:s",time());
include "connect.php";
function valid_ip($ip)
{
  if(!is_string($ip))
    return false;

  $ip_long = ip2long($ip);
  $ip_reverse = long2ip($ip_long);
    if($ip == $ip_reverse)
      return true;
    else
      return false;
} 
#print '<META HTTP-EQUIV="refresh" CONTENT="600">';
print '<body bgcolor="#FFFFCC" text="#000000">';
echo $now . "<br>";
print "<table border=1 bgcolor=#ffffcc>";
print "<tr> 
       <td>IP Address</td>
       <td>MAC Address</td>
       <td>IP Integer</td>
       <td>Status</td>
       </tr>";
$handle = fopen($arpfile,"r");
if ($handle) {
while (!feof($handle)) {
    $userinfo = fgets($handle, 4096);
    list($mytime, $myip, $mymac) = explode(',', $userinfo) ;
$mytime=substr($mytime, 3);
$mytime=str_replace(" CDT", "", $mytime);
list($junk, $mymonth, $myday, $mytime2, $myyear) = explode(' ', $mytime);

$mytime=$now;
    if (valid_ip($myip)==true)  
    {
       $ip2 = explode(".", $myip);
       $ip=$myip;
       $subnet = $ip2[0] . "." . $ip2[1] . "." . $ip2[2] . ".0";
       print "<td>$ip</td>";
       $mymac = trim($mymac);
       $mac = split(":",$mymac);
       $mymac = "";
       if (count($mac)==6) { 
       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 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>";
       print "<td>" . $mytime . "</td>";
       if (($mymac != 'ffffffffffff') && ($mymac != ''))
       {
       $stmt2 = "select SERIAL, IP_ADDRESS, SUBNET, MULTINICK, SENT_EMAIL, 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', MAC_ADDRESS = '$mymac', SUBNET = '$newsubnet', LAST_SEEN = '$mytime', IPNUM = '$iplong', SENT_EMAIL = '$now' where SERIAL = '$row2->SERIAL';"; 
                 }
                 else {
                 $stmt3 = "update arp_table set IP_ADDRESS = '$ip', MAC_ADDRESS='$mymac', SUBNET = '$newsubnet', LAST_SEEN = '$mytime', IPNUM = '$iplong' where SERIAL = '$row2->SERIAL';";
                 }
	         $sth3 = ibase_query($dbh, $stmt3);
                 if ($row2->SUBNET != $newsubnet) {
                      if ($row2->SENT_EMAIL == '') {
			 $mymd5 = $row2->MD5;
              		 include "mailmoved.inc";
		      }
                 }
	    } 
	    else {
                 $stmt3 = "update arp_table set LAST_SEEN = '$mytime', MAC_ADDRESS='$mymac' where SERIAL = '$row2->SERIAL';";
//echo $stmt3;
	         $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>';
                include "mailnew.inc";
                $sth3 = ibase_query($dbh, $stmt3);
       }
       print "</tr>";
       ibase_free_result($sth2);	
       }
     }
     }
}            
print "</table>";
fclose($handle);
{
echo $now . "<br>";

}

ibase_close($dbh);
}
?>

Return current item: Network Asset Management Archive