简体   繁体   中英

check if my teamspeak server is online

I want to add a teamspeak server status checker on my website, to check if it is online or offline

is there a way to do it in php, or jquery, javascript or in some other way?

I tried this, in php, but it does not work...

<?php 
function check_ts($ip, $tcp, $udp, $timeout=1) { //Function for the Check 
$fp = @fsockopen($ip, $tcp, $errno, $errstr, $timeout); 
if (!$fp) { 
  $stat = false; 
} else { 
  if (fgets($fp) == "[TS]\r\n") { 
 fputs($fp, "SEL $udp\r\n"); 
 if (fgets($fp) == "OK\r\n") { 
   $stat = true; 
 } else { 
   $stat = false; 
 } 
  } else { 
 $stat = false; 
  } 
  if (is_resource($fp)) 
 @fclose($fp); 
  return $stat; 
} 
} 

if (check_ts("my_WAN_ip", 10011, 9987)) { //Change IP, Query-Port and TS-Port 
 echo "<FONT COLOR=#00DD00><B>ONLINE</B></FONT>"; 
} else { 
 echo "<FONT COLOR=#DD0000><B>OFFLINE</B></FONT>"; 
} 
?>

I've also tried different ports found in , but it does not work 找到不同的端口,但是它不起作用

Please help

There is a Framework/Class that does exactly what you need. It's called 'TS3 PHP Framework' (see: https://www.planetteamspeak.com/ )

Example:

//Load Framework
require_once("libraries/TeamSpeak3/TeamSpeak3.php");

try {
   //Connect
   $ts3 = TeamSpeak3::factory("serverquery://query_user:query_pass@host:10011/?server_port=9987");

   //Server Status
   echo "Server Status: online";
}
catch(Exception $e) {
   //Errors (No connection)
   echo "Server Status: offline";
}

You can find more examples in the official documentation: http://docs.planetteamspeak.com/ts3/php/framework/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM