[PHP] Re: ping...

2002-12-13 Thread Paul Chvostek

On Fri, Dec 13, 2002 at 10:02:54AM -, Brian McGarvie wrote:
> 
> I can exec ping OK... but I need a way to ping and basically give me a OK or
> Not OK... any ideas?

This isn't really a PHP question, since ping is a command in the OS and
not in PHP itself.  And of course, you didn't mention what OS you run.

I run FreeBSD.  In FreeBSD, ping has options that could be used thusly:

$target="209.238.46.67";
exec("/sbin/ping -c 1 -t 3 $target", $junk, $ret);
if ($ret==0)// In shell, 0 means success
print "Wahoo!  I can see $ipaddr!\n";
else
print "Bummer...  $ipaddr seems to be down.\n";

The option -c specifies a "count" (the number of pings to send), and -t
specifies a timeout in seconds.  If your operating system is UNIX or
Linux, you can "man ping" from a shell to see what you need to do to
duplicate this functionality, or check out various OS man pages at
http://www.freebsd.org/docs.html#man .  If you're running a Microsoft
operating system, you're most likely out of luck.

-- 
  Paul Chvostek <[EMAIL PROTECTED]>
  Operations / Abuse / Whatever  +1 416 598-
  it.canada - hosting and development  http://www.it.ca/


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Re: Ping on Win32

2002-12-04 Thread Christopher J. Crane
Oh man...it's always the simple things you over look...thank you.
"Jason Wong" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> On Thursday 05 December 2002 04:08, Christopher J. Crane wrote:
> > This is the output I get and you can see that on the lines where the
loss
> > is 0% it still says 100%
>
> > >  if($Results2 = "100% loss") { print "
> Try
>
>   if ($Results2 == "100% loss")
>
> --
> Jason Wong -> Gremlins Associates -> www.gremlins.biz
> Open Source Software Systems Integrators
> * Web Design & Hosting * Internet & Intranet Applications Development *
>
> /*
> QOTD:
> "I never met a man I couldn't drink handsome."
> */
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Re: Ping on Win32

2002-12-04 Thread Jason Wong
On Thursday 05 December 2002 04:08, Christopher J. Crane wrote:
> This is the output I get and you can see that on the lines where the loss
> is 0% it still says 100%

> >  if($Results2 = "100% loss") { print " Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *

/*
QOTD:
"I never met a man I couldn't drink handsome."
*/


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: Ping on Win32

2002-12-04 Thread Christopher J. Crane
This is the output I get and you can see that on the lines where the loss is
0% it still says 100%
1 - Pinging 10.200.26.1 with 32 bytes of data:
2 - Request timed out.
3 - Ping statistics for 10.200.26.1:
4 - Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),
100% loss
5 - Approximate round trip times in milli-seconds:
6 - Minimum = 0ms, Maximum = 0ms, Average = 0ms



1 - Pinging 10.42.71.1 with 32 bytes of data:
2 - Reply from 10.42.71.1: bytes=32 time<10ms TTL=255
3 - Ping statistics for 10.42.71.1:
4 - Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),
100% loss
5 - Approximate round trip times in milli-seconds:
6 - Minimum = 0ms, Maximum = 0ms, Average = 0ms



1 - Pinging 10.200.48.1 with 32 bytes of data:
2 - Request timed out.
3 - Ping statistics for 10.200.48.1:
4 - Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),
100% loss
5 - Approximate round trip times in milli-seconds:
6 - Minimum = 0ms, Maximum = 0ms, Average = 0ms



1 - Pinging 10.42.1.1 with 32 bytes of data:
2 - Reply from 10.42.1.1: bytes=32 time=78ms TTL=254
3 - Ping statistics for 10.42.1.1:
4 - Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),
100% loss
5 - Approximate round trip times in milli-seconds:
6 - Minimum = 78ms, Maximum = 78ms, Average = 78ms




"Christopher J. Crane" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> I am trying to get a script to work. The basic idea is to go into a
database
> and grab some IP addresses for my LAN. Then for each one ping it using the
> exec command 1 time. If it is successful print output in green and if it
is
> not, print output in red. This is being done on a Win32 system. The ping
> command returns 6 lines for each IP address. I want to take line 4 and see
> if the result is "100% loss" or "0% loss". Below is what I have, but it
only
> seems to keep the first value and prints it out all the way through. I
know
> it's a problem with the looping somewhere, I just can't figure it out.
>
>  mysql_connect("localhost", "root", "") or die("Could not connect");
> mysql_select_db("Network");
> $Result = mysql_query("SELECT DISTINCT Subnet,SerialIPAddress FROM
> Locations") or die("Invalid query");
>   $output = array();
>  while ($Location = mysql_fetch_assoc($Result)) {
>   // ping some server five times and store output in array $output
>   exec("ping " . $Location["Subnet"] . " -n 1", $output);
>   $Count = 0;
>   while (list(,$val) = each($output)) {
>if($val != "") {
> $Count++;
> print "$Count - $val\n";
> if($Count == 4) {
>  list($Junk1, $Results1) = split("\(", $val);
>  list($Results2, $Junk2) = split("\)", $Results1);
>  if($Results2 = "100% loss") { print " color=\"red\">$Results2\n"; }
>  else { print "$Results2\n"; }
>  }
> }
>}
>   print "\n";
>   }
> mysql_free_result($Result);
> mysql_close();
> ?>
>
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php