?
Solved

IP Monitoring script

Posted on 2004-11-12
5
Medium Priority
?
1,347 Views
Last Modified: 2008-03-04
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

0
Comment
Question by:Sohel Rana
5 Comments
 
LVL 8

Accepted Solution

by:
inq123 earned 2000 total points
ID: 12569086
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
 
LVL 1

Expert Comment

by:pjargon
ID: 12569258
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
 
LVL 5

Expert Comment

by:basiclife
ID: 12585066
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
 
LVL 16

Author Comment

by:Sohel Rana
ID: 12594276
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
 
LVL 5

Expert Comment

by:basiclife
ID: 12602186
Hmm well to skip the use of the {}'s...

if(strpos(shell_exec("ping " . $addr[$i]),"TTL"))
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month15 days, 6 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question