Test Connectivity to Remote Machine Port

From Notes_Wiki
Revision as of 11:57, 12 June 2025 by Ansil (talk | contribs) (Created page with "Home > Windows > Windows OS Notes > Network Port and Connectivity Testing in Windows > Test Connectivity to Remote Machine Port == Test Connectivity to Remote Machine Port == Use the following PowerShell script to test TCP connectivity to a remote machine’s port: === Script === powershell $ipaddress = "10.11.21.59" $port = "10005" $connection = New-Object System.Net.Sockets.TcpClient($ipaddress, $port) if ($connecti...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Home > Windows > Windows OS Notes > Network Port and Connectivity Testing in Windows > Test Connectivity to Remote Machine Port

Test Connectivity to Remote Machine Port

Use the following PowerShell script to test TCP connectivity to a remote machine’s port:

Script

   powershell
   $ipaddress = "10.11.21.59"
   $port = "10005"
   $connection = New-Object System.Net.Sockets.TcpClient($ipaddress, $port)
   if ($connection.Connected) {
   Write-Host "Success"
   } else {
   Write-Host "Failed"
   }


This script attempts to create a TCP connection to the specified IP address and port. If the connection is successful, it prints Success, otherwise it prints Failed.

Example Output

 Success

This output means the connection to IP address 10.11.21.59 on port 10005 was successful.



Home > Windows > Windows OS Notes > Network Port and Connectivity Testing in Windows > Test Connectivity to Remote Machine Port