IP Monitoring script

Hi:

I'm lookinf for a script that monitors an IP address. If the IP address is pingable, the HTML page will display a green icon image and if the IP address is not pingable, the HTML page will display a red icon image.

After searching in the google I find the following script but I think it's not working properly :

<?php

// Change the URLs below to match the location of the status images
$online = "online.gif";
$offline = "offline.gif";

// Change the address & port
$addr = "www.yahoo.com";
$port = 80;

// No need to edit the lines below!
$churl = @fsockopen($addr, $port, $errno, $errstr, 20);
if (!$churl) {
header("Location: $offline");
} else {
header("Location: $online");
}
?>

rsdn

LVL 16
Sohel RanaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

inq123Commented:
Hi rsdn,

The script's idea basically works and I think it does work.  But I used the same function call and structure to make the following script and I think it'd be a better example or more suitable for your usage:

<?php

// list of addresses to test
$addr = Array("www.yahoo.com", "www.yahoo.com4");
$port = Array(80, 80);

// print out status of the addresses
for($i = 0; $i < count($addr); $i++)
{
  $churl = @fsockopen($addr[$i], $port[$i], $errno, $errstr, 20);
  if (!$churl)
  {
    print "$addr[$i] is offline<br>\n";
  }
  else
  {
    print "$addr[$i] is online<br>\n";
  }
}
?>

Cheers!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pjargonCommented:
Looks like this script only does web addresses (computers hosting http, maybe ftp).
To test if a box is pingable you might do a system('ping') and parse the results.. maybe get fancy with it.
0
basiclifeCommented:
To use the system ping comand, change:

  $churl = @fsockopen($addr[$i], $port[$i], $errno, $errstr, 20);
  if (!$churl)

to

  if(strpos(shell_exec("ping {$addr[$i]}"),"TTL"))

you can also get rid of the $port array

You can also play with the "ping <address>" command to specify maximum wait time and number of pings etc...
0
Sohel RanaAuthor Commented:
Hi :

@ inq123:

Thanks for the code it's working without graphics.

@ basiclife:

After I change those lines it shows me the following error. Thanks for your try.

Parse error: parse error, unexpected '}' in /home/web/public_html/matrix/temp/ipcheck_main.php on line 15

rsdn
0
basiclifeCommented:
Hmm well to skip the use of the {}'s...

if(strpos(shell_exec("ping " . $addr[$i]),"TTL"))
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.