How to check the local IP address used by system.Net.Sockets.TcpClient?

I would like to use the code as below

$c = "computername"
$p = PortNumber

#Create object for connecting to port on computer  
$tcpobject = New-Object System.Net.Sockets.TcpClient

#Connect to remote machine port                
$connect = $tcpobject.BeginConnect($c,$p,$null,$null) 

#Configure a timeout before quitting  
$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?

+4
source share
2 answers

After establishing a connection, you can access which gives , which provides , which you can transfer to and interrogate.TcpClient ClientSocketLocalEndpointIPEndpoint

, , . , , , .

+2

, , netstat -n -o, . .

0

All Articles