我有下面的脚本,它可以ping任何静态放入文件的IP,但是当我发布到它时它总是失败。
<?php
$server = $_POST['ip'];
if (!$socket = @fsockopen("$server", 80, $errno, $errstr))
{
echo "<font color='red'><strong>Offline!</strong></font>";
}
else
{
echo "<font color='green'><strong>Online!/strong></font>";
fclose($socket);
}
?>
答案 0 :(得分:1)
我添加了几个功能:
<?php
function port($Host, $Port = '')
{
if (strstr($Host, ':'))
{
if (strstr($Host, '/'))
{
$Output = substr($Host, strpos($Host, ':') +1, (strpos($Host, '/') -1) - strpos($Host, ':'));
}
else
{
$Output = substr($Host, strpos($Host, ':') +1);
}
}
if ((isset($Output)) and ($Output != ''))
{
return $Output;
}
else
{
if ($Port != '')
{
return $Port;
}
}
}
function server($Host)
{
if (strpos($Host, '//'))
{
$Host = substr($Host, strpos($Host, '//') +2);
}
if(strstr($Host,"/"))
{
$Host = substr($Host, 0, strpos($Host, "/"));
}
if(strstr($Host,":"))
{
$Host = substr($Host, 0, strpos($Host, ":"));
}
return $Host;
}
$Host = $_GET['ip'];
$Host = server($Host);
$churl = @fsockopen($Host, 80, $errno, $errstr, 10);
if (!$churl) {
echo("<div><b>Offline</b></div>");
}
else
{
echo("<div><b>Online</b></div>");
}
?>