Last active
February 2, 2018 22:14
-
-
Save 0x15f/47826da9d5bfb625aee855eeccda3f84 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$ip = 'ice.cosmicpe.me'; | |
$port = 19132; | |
$socket = @fsockopen("udp://" . $ip, $port, $errno, $errstr, 5); | |
socket_set_timeout($socket, 5); | |
socket_set_blocking($socket, true); | |
@fwrite($socket, "\xFE\xFD\x09\x10\x20\x30\x40\xFF\xFF\xFF\x01"); | |
$challenge = fread($socket, 4096); | |
$challenge = substr(preg_replace("/[^0-9-]/si", "", $challenge), 1); | |
$query = sprintf("\xFE\xFD\x00\x10\x20\x30\x40%c%c%c%c\xFF\xFF\xFF\x01", $challenge >> 24, $challenge >> 16, $challenge >> 8, $challenge >> 0); | |
@fwrite($socket, $query, strlen($query)); | |
$data = fread($socket, 4096); | |
@fclose($socket); | |
$response = implode([$data]); | |
$response = explode("\0", $response); | |
$response = array_filter($response); | |
$response = array_values($response); | |
$new = []; | |
foreach($response as $key => &$value) { | |
$value = preg_replace('/[^a-z\d _]/i', '', (string)$value); | |
if($value === "player_") { | |
$new['players'] = array_slice($response, $key + 1); | |
break; | |
} | |
$next = next($response); | |
$new[$value] = $next; | |
unset($response[$key + 1]); | |
} | |
print_r($new); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment