Difference between revisions of "Test Connectivity to Remote Machine Port"

From Notes_Wiki
(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...")
 
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
[[Main Page|Home]] > [[Windows]] > [[Windows OS Notes]] > [[Network Port and Connectivity Testing in Windows]] > [[Test Connectivity to Remote Machine Port]]
[[Main Page|Home]] > [[Windows]] > [[Network Port and Connectivity Testing in Windows]] > [[Test Connectivity to Remote Machine Port]]
 
== Test Connectivity to Remote Machine Port ==
== Test Connectivity to Remote Machine Port ==


Line 7: Line 6:
=== Script ===
=== Script ===


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




Line 31: Line 30:




[[Main Page|Home]] > [[Windows]] > [[Windows OS Notes]] > [[Network Port and Connectivity Testing in Windows]] > [[Test Connectivity to Remote Machine Port]]
[[Main Page|Home]] > [[Windows]] > [[Network Port and Connectivity Testing in Windows]] > [[Test Connectivity to Remote Machine Port]]

Latest revision as of 06:36, 18 June 2025

Home > Windows > 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 > Network Port and Connectivity Testing in Windows > Test Connectivity to Remote Machine Port