\n"; exec($COMMAND); } //TODO: if port 80 is alive, then set a hyperlink in the table below. //TODO: might want to switch to "ip -o neigh show" at some point instead of the antiquated 'arp' $arpn = `/usr/sbin/arp -n | grep -v "incomplete" | grep -v "Address" | sort`; //we use ` ` notation because it dumps all the output into a single variable. $temp = explode("\n", $arpn); array_pop($temp); //the last element is empty //"arp" and "in" don't show the box we're running it on, so we have to inject it manually... $local = preg_split("/[\s:]+/",exec("/sbin/ifconfig -a $ETH0 | /bin/grep \"inet addr:\""), -1, PREG_SPLIT_NO_EMPTY); $dot_quad_ip_eth0 = $local[2]; $local = preg_split("/\s+/",exec("/sbin/ifconfig -a $ETH0 | /bin/grep HWaddr"), -1, PREG_SPLIT_NO_EMPTY); $MAC_addr_eth0 = $local[4]; unset($local); $temp[] = $dot_quad_ip_eth0.' ether '.$MAC_addr_eth0." C $ETH0"; $m = 1; for($i = 0; $i < count($temp); $i++) { $arp = preg_split("/ /",$temp[$i], -1, PREG_SPLIT_NO_EMPTY); $complete_count++; $ip = $arp[0]; $macaddress = $arp[2]; $tempInterface[$i] = $arp[4]; $name = $leases[$ip]['client-hostname']; $name = str_replace("\"", "", $name); //we used to use the MAC as a unique key, but turns out VMWARE will show up on the host's mac $machine[$m] = new device($ip,$macaddress,$name,$tempInterface[$i], $incomplete, $TEST_CONNECTION); $machine[$m]->setLease($leases[$ip]['starts'], $leases[$ip]['ends']); $m++; } unset($temp); /////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////// //find the unique and active interfaces: //we could parse "cat /proc/net/dev" as well if we really wanted to know all interfaces, but generally //we would only care about the current ones in use. $tempInterface = array_unique($tempInterface); foreach ($tempInterface as $key => $value) { $temp = preg_split("/\s+/",exec("/sbin/ifconfig -a $value | /bin/grep HWaddr"), -1, PREG_SPLIT_NO_EMPTY); $MAC = $temp[4]; $temp = preg_split("/[\s:]+/",exec("/sbin/ifconfig -a $value | /bin/grep \"inet addr:\""), -1, PREG_SPLIT_NO_EMPTY); $IP = $temp[2]; $interface[$value] = new interfaceX($IP, $MAC, $value); } unset($temp); unset($tempInterface); /////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////// // read in the dhcp_map.ini file to map MAC addresses to images $mapFile = "./dhcp_map.ini"; if( $fp = @fopen($mapFile, "r") ) { while( $line = fgets($fp, 1024) ) if ($line{0} != "#") $tempMap .= $line; // strip out # comments } else echo "ERROR: Can't read ".$mapFile."
"; fclose ($fp); $map = explode("\n", $tempMap); //print "
"; print_r($map); print "
"; //for($i = 0; $i < count($map); $i++) foreach($map as $mapi) { //list($mac, $image, $name) = preg_split("/\s/",$map[$i], -1, PREG_SPLIT_NO_EMPTY); preg_match("/(..:..:..:..:..:..)\s+(\w+)\s+(.*)/i", $mapi, $matches); //print "
"; var_dump($matches); print "
"; list($junk, $mac, $image, $name) = $matches; foreach($machine as $key => $mobj) { //if ( array_key_exists($mac, $machine)) $machine[$mac]->setImage($image); if (!is_null($mac) && stripos($mobj->getMAC(),$mac) !== false) { $mobj->setImage($image); if ($name != '') $mobj->setName($name); //if ( isset($machine[$mac]) && $name != "" /*&& $machine[$mac]->getName() == ""*/) $machine[$mac]->name = $name; unset($mapi); } } } unset($tempMap); unset($map); /////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////// $numInterfaces = count($interface); $numMachines = count($machine); function cmp ($a, $b) { $tempA = ip2long($a->getIP()); $tempB = ip2long($b->getIP()); if ($tempA == $tempB) return 0; return ($tempA < $tempB) ? -1 : 1; } uasort($machine, "cmp"); ?>  Devices   ( complete / incomplete ) Devices on Network  

0) { ?> $object) { ?>

ping/nmap

IP

MAC

Name

Lease Starts
Lease Ends

Interface

.gif" BORDER="0" ALT="Device #"> .gif" BORDER="0" ALT="ping"> .gif" BORDER="0" ALT="nmap"> untested getIP()?> getMAC()?>    getName()?> lease_start?>
lease_end?>
<?=$object->getInterface()?>
No Devices found on the DHCP network

Edit the dhcp_map.ini file to change the icons
 Interfaces   active Interfaces on Network  

$object) { ?>

Interface

IP

MAC

<?=$object->name?> name?> IP?> MAC?>
> Test Connection

©2003- Daevid Vincent All Rights Reserved. Download dhcp_web.tgz (version: )