Reputation: 1220
I have the script below, and it can ping any IP statically put in the file, but when I post to it it always fails.
<?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);
}
?>
Upvotes: 0
Views: 1050
Reputation: 322
I've added several functions:
<?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>");
}
?>
Upvotes: 1