IP Monitoring script

Posted on 2004-11-12
Last Modified: 2008-03-04

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 :


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

// Change the address & port
$addr = "";
$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");


Question by:Sohel Rana
    LVL 8

    Accepted Solution

    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:


    // list of addresses to test
    $addr = Array("", "");
    $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";
        print "$addr[$i] is online<br>\n";

    LVL 1

    Expert Comment

    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.
    LVL 5

    Expert Comment

    To use the system ping comand, change:

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


      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...
    LVL 16

    Author Comment

    by:Sohel Rana
    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

    LVL 5

    Expert Comment

    Hmm well to skip the use of the {}'s...

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit ( and similar technologies have enjoyed wide adoption, making it possib…
    These days socially coordinated efforts have turned into a critical requirement for enterprises.
    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 …

    761 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

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now