Test Port 25 on server using ssh access or php script

Hi,

I have web hosting account on hostgator. I need port 25 enable.

So I login to server using SSH to check port and run php script but script says port 25 not enable and hostgator support team on chat says port 25 working fine.

I want to know how to check port 25 using SSH access or php script.

I am getting gateway timeout 504 error on below script.

$host = 'stackoverflow.com';
$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";
    }
}

Any idea?

Best Regards,

IMHO, using error suppression here is not a good idea when you’re trying to troubleshoot an error. In fact, I think it would be a good idea to get the most helpful error information you can.

From http://php.net/manual/en/function.fsockopen.php

Try these temporary changes

.....
//    $connection = @fsockopen($host, $port);
    $connection = fsockopen($host, $port, $errno, $errstr);
.....
//    echo '<h2>' . $host . ':' . $port . ' is not responding.</h2>' . "\n";
    echo '<h2>Error: ' . $errno . ' ' . $errstr . '</h2>' . "\n";
.....

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.