dousha1831 2014-06-04 18:38
浏览 54
已采纳

检查我的teamspeak服务器是否在线

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]
") { 
 fputs($fp, "SEL $udp
"); 
 if (fgets($fp) == "OK
") { 
   $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 this post, but it does not work

Please help

  • 写回答

1条回答 默认 最新

  • dongmi3203 2014-06-04 18:50
    关注

    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/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 quartus II 9.0闪退问题怎么解决啊,急
  • ¥20 求自动化运维语料数据集
  • ¥30 广告检测流量作弊案例 IDEA运行代码报错 连接不上metastore 检测了环境配置没有问题 请求远程解决加VX问细节问题 不加的不回复
  • ¥15 matlab图像融合代码被嫌弃太简单,求改进。第一步改成直接读取三张图片,不读取文件夹
  • ¥20 微处理器原理与应用(私有偿)
  • ¥50 8051单片机关于ADC0809的应用
  • ¥15 有没有能拿来练练手写完发给我
  • ¥15 禁止修改windows系统时间
  • ¥50 kinect连接win11笔电导致音视频设备消失
  • ¥15 python线性查找题