Skip to content

Categories:

TCP Port-check for open services

A little piece of code I created to do an accurate server check for world of warcraft private servers of World of Chris.

  1. <?php
  2. function flush_buffers() {
  3.     ob_end_flush();
  4.     ob_flush();
  5.     flush();
  6.     ob_start();
  7. }
  8.  
  9. // create a list of servers + ports to be checked
  10. $servers = array(
  11.     array("Zul'Aman 2.4.3""server4.wocserver.org""8420"2),
  12.     array("Allakhazam BG 2.4.3""server3.wocserver.org""8199"2),
  13.     array("Menethil 3.1.x""server3.wocserver.org""8129"2),
  14.     array("Kil'Jaeden 3.1.x""server2.wocserver.org""1337"2)
  15. );
  16.  
  17. ob_start();
  18.  
  19. echo "<table border=\"0\" width=\"500\">\n";
  20.  
  21. foreach($servers as $server) {
  22.     $status = (checkServer($server[1],$server[2],$server[3])?"online":"offline");
  23.     echo "<tr><td width=\"170\" align=\"right\"><img style=\"margin-bottom: 1px;\" src=\"".$status.".gif\" alt=\"".$status."\" align=\"absmiddle\" /></td><td>".$server[0]."</td></tr>\n";
  24.     flush_buffers();
  25. }
  26. echo "</table>";
  27.  
  28. // check for a connection on the given server / port and return boolean
  29. function checkServer($server$port$timeout 2) {
  30.     $fp = @fsockopen($server$port$errno$errstr$timeout);
  31.     if(!$fp)
  32.         return false;
  33.     else {
  34.         fclose($fp);
  35.         return true;
  36.     }
  37. }
  38. ?>

Example of this script can be found at www.dotcomgoed.nl/woc/.

Posted in PHP.

Tagged with , , , .


0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.