netfreak
02-17-2006, 06:44 PM
Got bored one night and did this script for part of my site. It is probably pretty basic, as I haven't done any php in a long time. In fact just by looking at it again the last "else if" could just be else {
<?php
$host = "preterhuman.net";
echo "<title>$host ping test</title>";
function do_ping($host, $fping, $p_result) {
$fping = exec("ping $host -c1 -w2 | awk '/time/ {print $8}' | head -1 | awk -F '=' '{print $2}'");
if ($fping <= "75" && $fping >= "0") {
$p_result = "<font color=green>GOOD</font>";
} else if ($fping <= "150" && $fping > "75") {
$p_result = "<font color=yellow>AVERAGE</font>";
} else if ($fping > "150") {
$p_result = "<font color=red>BAD</font>";
} else if ($fping == "") {
echo "<font face=Verdana>Host <b>$host</b> is not responding to ping.</font>";
exit;
}
echo "<font face=Verdana>Latency to host <b>$host</b> is <b>$fping ms.</b> This is <b>$p_result.</b></font>";
}
do_ping($host, $fping, $p_result);
?>
<?php
$host = "preterhuman.net";
echo "<title>$host ping test</title>";
function do_ping($host, $fping, $p_result) {
$fping = exec("ping $host -c1 -w2 | awk '/time/ {print $8}' | head -1 | awk -F '=' '{print $2}'");
if ($fping <= "75" && $fping >= "0") {
$p_result = "<font color=green>GOOD</font>";
} else if ($fping <= "150" && $fping > "75") {
$p_result = "<font color=yellow>AVERAGE</font>";
} else if ($fping > "150") {
$p_result = "<font color=red>BAD</font>";
} else if ($fping == "") {
echo "<font face=Verdana>Host <b>$host</b> is not responding to ping.</font>";
exit;
}
echo "<font face=Verdana>Latency to host <b>$host</b> is <b>$fping ms.</b> This is <b>$p_result.</b></font>";
}
do_ping($host, $fping, $p_result);
?>
