gooly
gooly

Reputation: 1341

PowerShell Socket-Server connected IP-Addresses

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!

Upvotes: 0

Views: 1086

Answers (1)

David Brabant
David Brabant

Reputation: 43519

You can get it through $client.Client.RemoteEndPoint

Upvotes: 1

Related Questions