PHP Script for PING

PHP - 2019-05-15 02:03:54

A 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.

The script is very simple:

// Script by Akensai

if (!$socket = @fsockopen("YOUR.IP.HERE", 80, $errno, $errstr, 30))
  echo "<font color='red'><strong>Offline!</strong></font>";
  echo "<font color='green'><strong>Online!/strong></font>";



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.

The personal work space of Les "Akensai" Barton, web designer, developer, gamer, musician, critic, and overall smart-ass. Thats me, and I write about whatever crosses my mind, whatever I have pestering the depths of my imagination.