you need to adopt this if you change the protocol!!
// (0x15 -> 21 is the object type id of EM_NET_STATUS_REQUEST)
$statusrequest="45 4d 5f 4d 50 01 00 00 00 00 01 00 00 00 01 00 00 00 15 00 00 00";
$statusrequest = str_replace(' ', '', $statusrequest);
$statusrequest = pack('H*', $statusrequest);
$handle = fsockopen("udp://".$an_ip, $a_port, &$errno, &$errstr, 2);
if (!$handle)
{
echo "$errno : $errstr
";
}
else
{
socket_set_timeout ($handle, 2);
$write = fwrite($handle,$statusrequest);
if (!$write)
{
echo "error writing to socket
";
}
else
{
$start = (float) array_sum(explode(' ', microtime()));
$data = fread($handle, 1000);
$end = (float) array_sum(explode(' ', microtime()));
$delta = $end - $start; //compute the 'ping'
fclose($handle);
if ($delta < 1.9)
{
$result->data = $data;
$result->ping = (int)($delta*1000);
}
else
{
$result->data = "";
$result->ping = ">2000";
}
return $result;
}
}
}
/* the output code */
if(isset($_REQUEST["ip"])) $ip = $_REQUEST["ip"]; else $ip="";
if(isset($_REQUEST["port"])) $port = $_REQUEST["port"]; else $port=0;
if(!($port + 0 <= 0) and !($ip==""))
{
$answer = contactServer($ip,$port);
echo "
Server status for $ip:$port | ping: $answer->ping ms |
', htmlspecialchars(urldecode($b[0])),' | ', htmlspecialchars(urldecode($b[1])), " |
Server $ip:$port timed out | ping: $answer->ping ms |