我想要一个PHP脚本,它允许你ping一个IP地址和一个端口号(ip:port).我发现了一个类似的脚本,但它只适用于网站,而不是ip:port.
<?php
function ping($host, $port, $timeout)
{
$tB = microtime(true);
$fP = fSockOpen($host, $port, $errno, $errstr, $timeout);
if (!$fP) { return "down"; }
$tA = microtime(true);
return round((($tA - $tB) * 1000), 0)." ms";
}
//Echoing it will display the ping if the host is up, if not it'll say "down".
echo ping("www.google.com", 80, 10);
?>
Run Code Online (Sandbox Code Playgroud)
我希望这个用于游戏服务器.
我的想法是我可以输入IP地址和端口号,然后我得到ping响应.
我想创建一个小的IF程序来检查Twitter是否可用(例如,与现在不同),并返回true或false.
救命 :)
可能重复:
使用PHP Ping一个IP地址并回显结果
你如何ping PHP中的IP地址.并给出结果,就像你在Windows中的cmd程序一样
<?php
system(‘ping -c 192.168.0.104’); // Ping IP address.<br>
echo “pinged”;<br>
?>
Run Code Online (Sandbox Code Playgroud) 我正在为我们公司使用的一个可怕的软件编写一个Web界面.该软件没有真正的用户界面,需要我们为我们的客户提供putty访问我们的系统甚至提取数据.我的Web界面必须运行一个exec();函数,它必须传递用户输入的一些变量.
$command = "report-call '$type' '$study' '$server' '$tag' '$specopt1' '$specopt2' '$specopt3' '$specopt4'";
$last_line = exec($command, $output, $returnvalue);
Run Code Online (Sandbox Code Playgroud)
现在我假设我可能只是从$command变量中删除任何分号并且是安全的,但我不确定,这就是为什么我在下个月上线之前在这里提出这个问题.
什么是最好的消毒方法$command?我确实需要在变量中使用一些特殊的字符 [ ] < > ! # $.