Skip to content

Instantly share code, notes, and snippets.

Created September 19, 2011 07:08
Show Gist options
  • Save anonymous/1226084 to your computer and use it in GitHub Desktop.
Save anonymous/1226084 to your computer and use it in GitHub Desktop.
<?php
$ip = "192.168.1.190"; // Minecraft IP
$port = "25566"; // Minecraft port
$fp = fsockopen($ip, $port, $errno, $errstr, 5); // Socket for connecting to server
if (!$fp) {
echo "Error";
} else {
$out = "\xFE"; // Hex needed for server info
fwrite($fp, $out);
while (!feof($fp)) {
$result .= fgets($fp, 128);
}
fclose($fp);
// Remove extra spaces between characters
$result = str_replace("\x00", "", $result);
$result = str_replace("\x1A", "", $result);
$result = str_replace("\xFF", "", $result);
$srvinfo = explode("\xA7",$result);
echo "motd: " . $srvinfo[0] . "\n";
echo "players: " . $srvinfo[1] . "\n";
echo "max_players: " . $srvinfo[2] . "\n";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment