Location: PHPKode > projects > PortWatcher > PortWatcher/MACSummary.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
            "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
	<link rel="stylesheet" href="index.css" type="text/css" />
	<title>MAC/IP Address Tools</title>
</head>
<?
 	include("config.php");
	$db = mysql_connect($dbserver, $dbuser, $dbpasswd);
	mysql_select_db($dbname, $db);
	if(!isset($limits_per_page))
	  $limits_per_page = 20;
	$links_per_page = 10;
?>
<body>
	<div class="header">
	<a href="http://www.lanifex.com"><img src="img/logo.jpg" alt=""></a>
	</div>
	<div class="menu">
			<a href="index.html"><span>Home</span></a>
			<a href="MACUpdate.php"><span>SNMP scan</span></a>
			<a href="MACTools.php"><span>DB review</span></a>
			<a href="switch_man.php"><span>Switch management</span></a>
	</div>
	<div class="content">
	<?	$sql = 'SELECT * FROM switches ORDER BY dnsname';
		$macportResult = mysql_query($sql);
		echo "<h2>Switch statistics</h2>";

		if ($macportResult)
		{
			echo "<table class=\"general\" CELLSPACING=\"0\">"; 
			echo "<tr>\n";
			echo "<td><strong>&nbsp;Name&nbsp;</strong>\n";
			echo "<td><strong>&nbsp;IP&nbsp;</strong>\n";
			echo "<td><strong>&nbsp;OS&nbsp;</strong>\n";
			echo "<td><strong>&nbsp;Status&nbsp;</strong>\n";
			echo "<td><strong>&nbsp;Real status&nbsp;</strong>\n";
			echo "<td><strong>&nbsp;MAC Count&nbsp;</strong>\n";
			echo "<td><strong>&nbsp;Last Polled&nbsp;</strong>\n";
			echo "</tr>\n";
			
			while ($macportrow = mysql_fetch_array($macportResult)) 
			{
				$last_polled = $macportrow['last_polled'];
				$os = $macportrow['OS'];
				$mac_count = 0;
				$sql_count = "SELECT * FROM macport WHERE bsipaddress ='".$macportrow['ipaddress']."';";
				$Result = mysql_num_rows(mysql_query($sql_count));
				
				//$line = exec('ping -c5 -i0.2 -f '.$macportrow['ipaddress'], $bla,  $ping_result);
				$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
				socket_set_nonblock($sock);
				socket_connect($sock, $macportrow['ipaddress'], 23);
				socket_set_block($sock);
				switch(socket_select($r = array($sock), $w = array($sock), $f = array($sock), 5))
				{
				        case 2:
				                $ping_result = 1;
				                break;
				        case 1:
				                $ping_result = 0;
				                break;
				        case 0:
				                $ping_result = 1;
				                break;
				}
				
				if ($ping_result == 0)
				{
					$message = "Reachable";
					$scolor = "green";
				}
				else
				{
					$message = "Unreachable";
					$scolor = "red";
				}
						
				if($Result == NULL)
					$Result = '0';

					
				if($os == "")
					$os = "&nbsp;";	

				if($last_polled == "0000-00-00 00:00:00")
					$last_polled = '<font color=red>Never Polled</font>';

				if($macportrow['status'] == 0)
				{
					$status = "off";
					$color = "red";
				}
				else 
				{
					$color = "green";
					$status = "on";
				} 
				echo "<tr><td><a HREF=\"/portwatcher/MACTools.php?BaystackList[]=".$macportrow['ipaddress']."&submitMacValue=7\">".$macportrow['dnsname']."</a></td>";
				echo "<td>".$macportrow['ipaddress']."</td>";
				echo "<td>".$os."</td>";
				echo "<td><font color=$color >$status</font></td>";
				echo "<td><font color=$scolor >$message</font></td>";
				echo "<td>$Result</td>";
				echo "<td>$last_polled</td></tr>";
			}
			echo("</table>");
		}
		else
		{
			echo "<p>Unable to find any switches.</p>";
		}
		mysql_close($db);
	?>
	<div class="clear"></div>
	</div>
	<div class="footer"></div>
</body>
</html>
Return current item: PortWatcher