• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Status checker.

Paxton

Banned User
Joined
Feb 23, 2008
Messages
4,110
Reaction score
48
Location
London, UK
Alrgith, so I made simple script which checks status of server and gets info from it.

PHP:
<?
	if(isset($_POST['submit'])){
		if(empty($_POST['address']))
		echo "Address field is empty.";
			else {
			$address = htmlentities(strtolower($_POST['address']));
			$port = (int)$_POST['port'];
				if(empty($_POST['port']))$port = 7171;
				 @$sock = fsockopen ($address, $port, $errno, $errstr, 1);
				 if(!$sock) echo "Server did not respond."; else {
				 $info = chr(6).chr(0).chr(255).chr(255).'info';
				fwrite($sock, $info);
				$data='';
				while (!feof($sock))$data .= fgets($sock, 1024);
				fclose($sock);
				preg_match('/players online="(\d+)" max="(\d+)"/', $data, $matches);
				$players = ''.$matches[1].' / '.$matches[2];
				preg_match('/uptime="(\d+)"/', $data, $matches);
				$h = floor($matches[1] / 3600);
				$m = floor(($matches[1] - $h*3600) / 60);
				$uptime = ''.$h.'h '.$m.'m';
				preg_match('/monsters total="(\d+)"/', $data, $matches);
				$monsters = ''.$matches[1];
				preg_match('#<motd>(.*?)</motd>#s', $data, $matches);
				$motd = ''.$matches[1];
				if(empty($players) or $players == " / ") $players = "??? / ???";if(empty($uptime)) $uptime = "???";if(empty($monsters)) $monsters = "???";if(empty($motd)) $motd = "???";
				echo "<fieldset style='border: 1px groove black;'><legend>Response</legend>Response for $address on port $port<br>Players: $players <br> Uptime: $uptime<br> Monsters: $monsters<br> MOTD: <i>$motd</i></fieldset>";
				 }
			}
		} else $port = 7171;
?>
<form action='<?=$SERVER['PHP_SELF'];?>' method='post'>
Server address:<br><input type='text' name='address' value='<?=$address;?>' style='border: 1px groove black;'>:<input style='border: 1px groove black;' type='text' value='<?=$port;?>' name='port' size='4'><br><input type='submit' name='submit' value='Check'>
</form>

ebact1in80jwzjvivyl.png
 
Just paste this code anywhere, in any file.

Where u paste there u have it simple.
 
To use it just open notepad, copy - paste the script, save it as Filename.php (add .php in the end) and put it on your host (e.g. xampp or some hosting service)

Anyways, quite cool thing :)
 
Hmm.. I copy the code into a php file, I have named it checker.php.
I copy into a xampp htdocs folder and run http://127.0.0.1/checker.php

and I see:

errorxz.jpg


Hm, why it doesent work?
Here:
PHP:
<?php
    if(isset($_POST['submit'])){
        if(empty($_POST['address']))
        echo "Address field is empty.";
            else {
            $address = htmlentities(strtolower($_POST['address']));
            $port = (int)$_POST['port'];
                if(empty($_POST['port']))$port = 7171;
                 @$sock = fsockopen ($address, $port, $errno, $errstr, 1);
                 if(!$sock) echo "Server did not respond."; else {
                 $info = chr(6).chr(0).chr(255).chr(255).'info';
                fwrite($sock, $info);
                $data='';
                while (!feof($sock))$data .= fgets($sock, 1024);
                fclose($sock);
                preg_match('/players online="(\d+)" max="(\d+)"/', $data, $matches);
                $players = ''.$matches[1].' / '.$matches[2];
                preg_match('/uptime="(\d+)"/', $data, $matches);
                $h = floor($matches[1] / 3600);
                $m = floor(($matches[1] - $h*3600) / 60);
                $uptime = ''.$h.'h '.$m.'m';
                preg_match('/monsters total="(\d+)"/', $data, $matches);
                $monsters = ''.$matches[1];
                preg_match('#<motd>(.*?)</motd>#s', $data, $matches);
                $motd = ''.$matches[1];
                if(empty($players) or $players == " / ") $players = "??? / ???";if(empty($uptime)) $uptime = "???";if(empty($monsters)) $monsters = "???";if(empty($motd)) $motd = "???";
                echo "<fieldset style='border: 1px groove black;'><legend>Response</legend>Response for $address on port $port<br>Players: $players <br> Uptime: $uptime<br> Monsters: $monsters<br> MOTD: <i>$motd</i></fieldset>";
                 }
            }
        } else $port = 7171;
?>
<form action='<?php echo $SERVER['PHP_SELF'];?>' method='post'>
Server address:<br><input type='text' name='address' value='<?php echo $address;?>' style='border: 1px groove black;'>:<input style='border: 1px groove black;' type='text' value='<?php echo $port;?>' name='port' size='4'><br><input type='submit' name='submit' value='Check'>
</form>
 
#Zisly

under:
PHP:
fclose($sock);
add:
PHP:
$get = simplexml_load_file($data);

and you easy get's data like:
PHP:
echo "Players: {$get->players["online"]} / {$get->players["max"]}<BR>";
 
You've used some shortcuts, for instance "<?=4var;?>" instead of the proper way, "<?php echo $var; ?>".

Which meant that I had to edit some of the script, running my php server in uberstrict mode :p
 
Back
Top