Francisco Fernandez Garrido Francisco Fernandez Garrido - 1 year ago 111
PHP Question

Need to check IP reachability via PHP or SSH (can't use ping though)

I need to check if my hosting server can reach certain IPs that I need to work with.
I have a shared hosting plan and, although I have access to SSH, the PING function is not available.
I've tried several php scripts but to no avail. Most of them relied on executing PING via shell.

Is there any way I can check this without using PING? I tried using the CURL function (in PHP) but it doesn't seem to work with IPs.

Any help would be very much appreciated.

hd1 hd1
Answer Source

Try this, it connects to port 22, which is the reserved port for ssh:

// By: Spicer Matthews <>
// Company: Cloudmanic Labs, LLC
// Date: 5/19/2011
// Description: This is a client to the echo server. It will send 10 test commands, and echo the server response.
//                          Run it from the command line "php client.php".
$address = '';
$port = '22';

$fp = fsockopen($address, $port, $errno, $errstr, 300);
if(! $fp) 

The response codes may need to be changed, as necessary.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download