Spodobał mi się pomysł skryptu BzikOS'a i postanowiłem napisać swój, podobny - ale wyposażony w logowanie statusu komputerów.

Ma zdecydowanie mniejsze możliwości (m.in tylko metoda ping'u) i jest ciężej go dopasować pod siebie, jednak może komuś się przyda.

[php:1:d4f7b7eb31]<?php
//===========================================================
//===========================================================
// SETTINGS
//===========================================================
//===========================================================
set_time_limit (0);


$adresy["192.168.0.1"] = "Rafał";
$adresy["192.168.0.2"] = "Robert";
$adresy["192.168.0.3"] = "Magda";
$adresy["192.168.0.4"] = "Dominik";




$time = microtime();
$time = explode(" ",$time);
$time = $time[1] + $time[0];
$time1 = $time;
//===========================================================
//===========================================================
// TERAZ
//===========================================================
//===========================================================
function teraz ($adresy)
{
print("<table>");


print("<tr style="height: 30px;">");
print("<td style="width: 20px;">&nbsp;</td>");
print("<td style="width: 90px;"><span class="b">ip</span></td>");
print("<td style="width: 90px;"><span class="b">nazwa</span></td>");
print("<td style="width: 50px;"><span class="b">status</span></td>");
print("</tr>");


$temp = 0;
foreach( $adresy as $ip => $nazwa )
{
$temp++;
print("<tr style="height: 30px;">");
print("<td style="width: 20px;">" . $temp . "</td>");

print("<td style="width: 90px;">" . $ip . "</td>");

print("<td style="width: 90px;">" . $nazwa . "</td>");

$status = "<span class="red">down</span>";
$ping = shell_exec("ping -n 1 -w 10 $ip");
if( !ereg("100%", $ping ) )
$status = "<span class="green">up</span>";


print("<td style="width: 50px;">" . $status . "</td>");



print("</tr>");
}

print("</table>");
}




//===========================================================
//===========================================================
// ZAPISZ
//===========================================================
//===========================================================
function zapisz ($adresy)
{
$godzina = date("H");
$minuty = date("i");

if ($minuty == 59)
{
$minuty = "00";
$godzina++;
}
elseif ($minuty == 01)
$minuty = "00";
elseif ($minuty == 29)
$minuty = 30;
elseif ($minuty == 31)
$minuty = 30;

$linia = "$godzina:$minuty";

foreach( $adresy as $ip => $nazwa )
{
$status = "off";
$ping = shell_exec("ping -n 1 -w 10 $ip");
if( !ereg("100%", $ping ) )
$status = "on";

$linia = $linia . "|" . $nazwa . ":" . $status;
}


$plik = fopen("logs.txt", "a");
fputs($plik, "n$linia");
fclose($plik);


}




//===========================================================
//===========================================================
// LOGS
//===========================================================
//===========================================================
function logs ($adresy)
{


$plik = fopen("logs.txt", "r");
if ($plik)
{
$temp = 0;
while(!feof($plik))
{
fgets($plik, 255);
$temp++;
}
fclose($plik);
$start = $temp - 24;
}


$plik = fopen("logs.txt", "r");
if ($plik)
{
$temp = 0;
while(!feof($plik))
{
$linia = fgets($plik, 255);
if ($temp >= $start - 1)
{
$linia = str_replace("n", "", $linia);
$linia = str_replace("rn", "", $linia);
$explode = explode("|", $linia, 2);
$godzina = $explode[0];
$reszta = $explode[1];
$reszta = explode("|", $reszta);


$wyjscie = null;
foreach( $reszta as $nr => $wartosc )
{
$explode = explode(":", $wartosc);
$temp0 = $explode[0];
$temp1 = $explode[1];
$wyjscie[$temp0] = $temp1;
}
$logs[$godzina] = $wyjscie;

}
$temp++;
}
fclose($plik);
}



print("<table>");


print("<tr style="height: 30px;">");
print("<td>&nbsp;</td>");
foreach( $logs as $godzina => $stan )
print("<td style="width: 42px;">" . $godzina . "</td>");
print("</tr>");



foreach( $adresy as $ip => $nazwa )
{
if ($nazwa == null)
$nazwa = "&nbsp;";
print("<tr style="height: 25px;">");
print("<td><span class="b">" . $nazwa . "</span></td>");
foreach( $logs as $godzina => $stan )
{
if( $stan[$nazwa] == "on" )
$temp = "<span class="green">up</span>";
elseif( $stan[$nazwa] == "off" )
$temp = "<span class="red">down</span>";
else
$temp = "??";
print("<td style="width: 42px;">" . $temp . "</td>");
}
print("</tr>");
}


print("</table>");

}




//===========================================================
//===========================================================
// XHTML
//===========================================================
//===========================================================
?>









<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
<title> LAN status </title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-2" />
<meta http-equiv="refresh" content="60" />
<meta name="author" content="Rafal Milecki" />
<style type="text/css">
<!--
.text { font-family: Verdana; color: #595959; font-size: 9pt; text-decoration:none; font-weight: normal; }


.i { font-style: italic; }
.u { text-decoration: underline; }
.b { font-weight: bold; }


.green { color: #3E9130;}
.red { color: #FF0000;}


body {
padding: 0px;
margin: 20px;
}


img {
border: 0px;
}


table {
border-right: 1px dotted #000000;
border-bottom: 1px dotted #000000;
}


td {
text-align: center;
border-left: 1px dotted #000000;
border-top: 1px dotted #000000;
}


.teraz {
position: relative;
width: 100%;
margin-top: 0px;
margin-left: auto;
margin-right: auto;

text-align: left;
font-family: Verdana; color: #2D2D2D; font-size: 9pt; text-decoration:none; font-weight: normal;
}


.logs {
position: relative;
width: 100%;
margin-top: 40px;
margin-left: auto;
margin-right: auto;

text-align: left;
font-family: Verdana; color: #2D2D2D; font-size: 9pt; text-decoration:none; font-weight: normal;
}


.stopka {
position: relative;
width: 100%;
margin-top: 40px;
margin-left: auto;
margin-right: auto;

text-align: left;
font-family: Verdana; color: #2D2D2D; font-size: 9pt; text-decoration:none; font-weight: normal;
}
-->
</style>
</head>
<body>




<?php
$plik = fopen("logs.txt", "a+");
while(!feof($plik))
$temp = fgets($plik, 255);
fclose($plik);
$temp = explode("|", $temp);
$temp = explode(":", $temp[0]);
$godzina = $temp[0];
$minuty = $temp[1];


if ($minuty == 59)
{
$minuty = "00";
$godzina++;
}
elseif ($minuty == 01)
$minuty = "00";
elseif ($minuty == 29)
$minuty = "30";
elseif ($minuty == 31)
$minuty = "30";


$temp = $godzina . ":" . $minuty;


if( ((date("i") == 29)or(date("i") == 30)or(date("i") == 31)or(date("i") == 59)or(date("i") == 00)or(date("i") == 01)) and ($temp != date("H:i")) )
zapisz($adresy);
?>


<div class="teraz">
<span class="b">Teraz:</span>
<?php
teraz($adresy);
?>
</div>


<div class="logs">
<span class="b">Logs:</span>
<?php
logs($adresy);
?>
</div>


<div class="stopka">
<span class="b">Inne:</span><br />

<?php
$time = microtime();
$time = explode(" ",$time);
$time = $time[1] + $time[0];
$time2 = $time;

printf("wygenerowano w: %.3f sec",$time2 - $time1);
?>
<br /><a href="http://validator.w3.org/check/referer"><img src="http://www.w3.org/Icons/valid-xhtml11" alt="" /></a>
</div>



</body>
</html>[/php:1:d4f7b7eb31]