I would like to use the code as below
$c = "computername"
$p = PortNumber
$tcpobject = New-Object System.Net.Sockets.TcpClient
$connect = $tcpobject.BeginConnect($c,$p,$null,$null)
$wait = $connect.AsyncWaitHandle.WaitOne($TCPtimeout,$false)
check destination port. The code will run as part of the PowerShell script.
If you can verify which local IP address or (at least) the local network adapter is used to initiate the connection?
source
share