问题描述:

I started a socket-server by

 $endpoint = new-object System.Net.IPEndPoint ([system.net.ipaddress]::any, $port)

$listener = new-object System.Net.Sockets.TcpListener $endpoint

Any client with any IP-Address (subject to change) is able to connect.

How do get the IP-Addresse of a connected client after it has connected and was accepted:

 if ( $listener.Pending()) {

$client = $listener.AcceptTcpClient()

$stream = $client.GetStream();

$writer = New-Object System.IO.StreamWriter $stream

$writer.AutoFlush = $true

...

}

Unfortunately $client.IPAddress() (error) or $client.IPAddress (nothing) do not exists

Thanks in advance!

网友答案:

You can get it through $client.Client.RemoteEndPoint

相关阅读:
Top