Education | Gaming | Internet | Reviews | Tech | Tutorials | WhoIS Lookup | SSL Checker  

PHP Script: Ping Online/Offline

Posted by Akensai on May 15, 2012 in Tutorials and has 18 replies.  

Ping StatusA few days ago I came across a need to have a script to ping an IP:Port to see if a list of machines where online or offline. The basis for this was for a list of about 60 dedicated servers that I wanted to be able to load a page to see if any where down. After a few hours of research I came up with the following which will ping an IP and Port then change the text color to represent online or offline.

View Demo
The script is very simple:

For those of you unaware of how PHP works, the script will actually mask your IP:Port that is queried, so no worries on someone finding the open port!

This can be used for just about anything, not just web. I use it to monitor a few FTP servers (port 21) and another for a couple of game servers. The possibilities are pretty much endless.

  • Robbotwobbo

    Just what I was looking for, thanks!

  • Rgreene

    Thank you.

  • Robertd12

    Thanks for the handy script!

  • xRepinsSporx

    any way to script that so it can do more then one server?

    • Akensai

      You can simply paste the script in a .php multiple times changing the ip/port where needed. Some will complain that it’s not very “professional” but since it’s fsock the results of being all in one script and being pasted over multiple times is the same since it will have to connect each time the page is loaded anyways. I wouldn’t suggest having more than 10 or so on a single page.

      Best bet would be to create separate .php files for each one and iframe them to your main list so they each load independently, otherwise more than 5-6 on a single page may take some load time.

  • Shaun

    Don’t know if you will answer but i’m quite new to php. Would there be a way to put the result into some sort of variable so you can just call $status or something?

    • shaun

      Aha no problem I found out how ^^
      (Code modified a little)

      • shaun

        Doesn’t let you post code :( 


    Wow,, its work

  • Glowafterlife

    You think you could make one were you type in a IP


  • Erik

    Can someone tell me how to implement multiple servers in this script? Ty

  • ntking

    Спасибо огромной, работает!

  • agugu

    i noob to php but how does iframe work ? any sample for multi ip address (i want to add 15-20 ipaddress. tyvm sir

    • Sandeep Verma

      i need add 200 ips

      • Dominik

        // Script by Akensai

        $ips = array('IPno1','IPno2','IPno3'); // Here'll be your ips

        if (!$socket = @fsockopen($ips, 80, $errno, $errstr, 30))
        echo "Offline!“;
        echo “Online!/strong>”;



        Here you are :))

        • uniquerelease

          can help how actually to add more thn 1 ip please? and what does mean 30)) ? What function of 30? Thanks.

  • Kamran

    Yes just exactly what I was looking for, except if it could do ICMP Ping rather than testing a port…

  • jerry osullivan

    Please is their any way to adjust script to icmp ping as i have bonded connection that you can’t ping port to it would be very help full. I have used it on the ones i can ping and works great thanks