1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| <?php
// Constant
define('PACKET_SIZE', '1400');
define('SERVERQUERY_GETCHALLENGE', "\xFF\xFF\xFF\xFF\x57");
define ('REPLY_GETCHALLENGE', "\x41");
// Ip address and port
$_ip = '84.16.241.115';
$_port = '28200';
// Open a connection with server
$socket = stream_socket_client('udp://'.$_ip.':'.$_port, $errno, $errstr, 30);
stream_set_timeout($socket, 1, 0);
// Send command to server
$cmd = SERVERQUERY_GETCHALLENGE;
$length = strlen($cmd);
fwrite($socket, $cmd, $length);
// Get response from server
$response = fread($socket, PACKET_SIZE);
echo $response;
echo '<br>';
if (empty($response))
{
echo 'Server Offline';
}
else
{
echo 'Server Online';
}
// Send command to server
$cmd = SERVERQUERY_INFO;
$length = strlen($cmd);
fwrite($socket, $cmd, $length);
// Get response from server
$response = fread($socket, PACKET_SIZE);
// Clean response
$pattern = "#\xFF\xFF\xFF\xFF".REPLY_INFO."#";
$response = preg_replace($pattern, '', $response);
echo $response;
?> |
Partager