Jump to content

check if port on remote server is open from client side


cappa1983

Recommended Posts

Hi All - I'm trying to see if the below is possible using PHP.

is it possible for php to allow a user to check if a port is open/listening on a remote server/PC, from their local machine. I've seen scripts on the web that talk about opening cmd.exe - this won't work as not all of my users will be on windows. Also saw fsock.. but the remote server is not serving http page(s). Also saw telnet, but again, some of my users may not have that windows feature enabled.

Desired workflow:

1. user enters the server hostname/IP and a port

2. my php webapp will emulate checking if that hostname and port is open from the local user's computer.

 

thanks!

Link to comment
Share on other sites

  • 2 years later...
On 1/12/2020 at 3:18 PM, cappa1983 said:

Hi All - I'm trying to see if the below is possible using PHP.

is it possible for php to allow a user to check if a port is open/listening on a remote server/PC, from their local machine. I've seen scripts on the web that talk about opening cmd.exe - this won't work as not all of my users will be on windows. Also saw fsock.. but the remote server is not serving http page(s). Also saw telnet, but again, some of my users may not have that windows feature enabled.

Desired workflow:

1. user enters the server hostname/IP and a port

2. my php webapp will emulate checking if that hostname and port is open from the local user's computer.

 

thanks!

With this routine you can check severals hosts and put in a table (must insert an up and down image).

 

<?php
$counterx = 0;

echo "<table border=2 align=center>";
echo "<th>Servidor Externo</th>";
echo "<th>Est.</th>";
echo "<th>Puerto</th>";
echo '<br>';
echo '<br>';


$hostx[1]    =  'www.domain1.com';
$hostx[2]    =  'www.domain2.com';
$hostx[3]    =  'www.domain3.com';


$port[1] = '80';
$port[2] = '443';
$port[3] = '21';


foreach ($hostx as $value) 
{
    $counterx = $counterx + 1;
    
    $connection = @fsockopen($hostx[$counterx], $port[$counterx]);

    if (is_resource($connection))
    {
       
        echo "<tr><td width=150 style='font-size:80%'>$hostx[$counterx]</td>"; 
        echo "<td width=10><img src='up.png'></td>";
        echo "<td width=20 style='font-size:80%'>$port[$counterx]</td>"; 
        

        fclose($connection);
    }

    else
    {
        echo "<tr><td width=150 style='font-size:80%'>$hostx[$counterx]</td>"; 
        echo "<td width=10><img src='down.png'></td>";
        echo "<td width=20 style='font-size:80%'>$port[$counterx]</td>"; 


}
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.