PHP Script to check for open ports

PHP Script to check for open ports

Here is a simple PHP script that you can use to test if a port is open on the server or not.

' . $host . ':' . $port . ' ' . '(' . getservbyport($port, 'tcp') . ') is open.' . "\n";
 
        fclose($connection);
    }
 
    else
    {
        echo '

' . $host . ':' . $port . ' is not responding.

' . "\n"; } } ?>

And if you want to check for open ports on another server, get it’s IP address and put it instead of the $_SERVER[‘SERVER_ADDR’]; like this:

$host = $_SERVER['SERVER_ADDR'];
$host = '142.250.190.46';

Create a new file e.g. port-check.php and put the above snippet inside then open it in your browser. that’s it.

The output will be similar to this:

open ports
open ports
Join the discussion

I enjoy constructive responses and professional comments to my posts, and invite anyone to comment or link to my site.

2 comments
%d bloggers like this: