Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the copy-the-code domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/www/html/pcx3.com/wp-includes/functions.php on line 6121
PHP Script to check for open ports - PC✗3
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.

<?php


$host = $_SERVER['SERVER_ADDR'];
$ports = array(21, 25, 80, 81, 110, 443, 3306);
 
foreach ($ports as $port)
{
    $connection = @fsockopen($host, $port);
 
    if (is_resource($connection))
    {
        echo '<h2>' . $host . ':' . $port . ' ' . '(' . getservbyport($port, 'tcp') . ') is open.</h2>' . "\n";
 
        fclose($connection);
    }
 
    else
    {
        echo '<h2>' . $host . ':' . $port . ' is not responding.</h2>' . "\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
whoami
Stefan Pejcic
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