如何执行命令telnet php

时间:2014-05-15 16:50:55

标签: php

我有一个代码用telnet连接到teamspeak服务器。 有人可以帮我发送命令吗?

我的代码:

<?php
$ip = 'localhost';
$result = '';
$fp = fsockopen($ip, 10011); 
echo fgets($fp); 
      fputs($fp,"help");
      $result=fread($fp,1024); 
fclose($fp);
echo nl2br($result);
?>

我想发送命令&#34; help&#34;

此代码仅返回:

TS3 
Welcome to the TeamSpeak 3 ServerQuery interface, type "help" for a list of commands and "help " for information on a specific command.

1 个答案:

答案 0 :(得分:4)

类似的东西:

<?php
$socket = fsockopen("localhost", "10011", $errno, $errstr); 

if($socket) 
{ 
    echo "Connected <br /><br />"; 
} 
else 
{ 
    echo "Connection failed!<br /><br />"; 
} 

fputs($socket, "help \r\n"); 

$buffer = ""; 

while(!feof($socket)) 
{ 
    $buffer .=fgets($socket, 4096); 
} 

print_r($buffer); 
echo "<br /><br /><br />"; 
var_dump($buffer); 

fclose($socket); 
?> 

我在你的代码中添加了更多内容,不可能