Reply to RE: [PHP] exec ping

Your name:

Reply:


Posted by "Daevid Vincent" on 08/23/05 23:29

Here's one I wrote:

/**
* Checks the status of an address as being "U" or "D".
*
* @access public
* @return "U" or "D"
* @param $TargetRange the dotted quad address to check
* @param $DEBUG debugging output. default is false.
* @since 3.0
*/
function CheckIP($TargetRange, $DEBUG = false)
{
$Status = "?";
if (preg_replace("/[^0-9.A-Za-z]/","",$TargetRange) == $TargetRange)

{
$res = exec("ping -n -c 1 -w 1 -q
".escapeshellarg($TargetRange));
//if (preg_match("/round-trip min\/avg\/max\/mdev/",$res)) {
$Status = "U"; } else { $Status = "D"; }
if ($DEBUG) echo $TargetRange." ping = ".$res."<BR>";
if ( strstr($res,"100% packet loss") )
{
$Status = "D";

//if ping fails, it could still be there, so try
nmap as a sanity check.
$res = exec("nmap -sP -n -r
".escapeshellarg($TargetRange));
if ($DEBUG) echo $TargetRange." nmap =
".$res."<BR>";
if ( strstr($res,"1 host up") ) $Status = "U";
}
else
$Status = "U";
}

if ($DEBUG)
{
echo "CheckIP $TargetRange Status = ".$Status."<P>";
echo str_pad(" ", 300);
flush();
}
return $Status;
} //CheckIP

> -----Original Message-----
> From: Juan Pablo Herrera [mailto:jpherrera@gmail.com]
> Sent: Saturday, August 20, 2005 11:35 PM
> To: Jasper Bryant-Greene
> Cc: php-general@lists.php.net
> Subject: Re: [PHP] exec ping
>
> On 8/21/05, Jasper Bryant-Greene <jasper@bryant-greene.name> wrote:
> > Juan Pablo Herrera wrote:
> > > Thanks Jasper,
> > > well, i need make a explode of results of the ping. The
> idea is check
> > > a host and when the host don´ t response send a email.
> > > I don't explode the result of the ping.
> >
> > If it was me, I'd try opening a socket connection to the
> host instead,
> > and check to see if you can connect or not. Whether or not that is
> > suitable to your application I don't know...
> >
> > Jasper
> >
>
> Hi!
> I did following script:
>
> <?php
> // Exec a ping
> exec('ping -c 5 192.168.236.3',$result);
> // Take result from icmp seq = 2
> $icmp = strpos($result[2], 'time=');
>
> $icmp = $icmp + 5;
>
> $fin = strpos($result[2], 'ms');
> // This is my end
> $fin = $fin - $icmp;
> // I take only the ms time
> $text = substr($result[2],$icmp,$fin);
> // Strip whitespace
> $ms = trim($text);
>
> if (!is_numeric($ms)) {
> $a = 'myemail@host.com';
> $asunto = "Servidor Caido";
> $mensaje = "Posible caida del servidor. No responde PING.";
> mail($a, $asunto, $mensaje);
> }
>
> ?>
>
> It's very simple, but i think that is working. I will add
> other options.
>
> JP
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация