websocket-sharp icon indicating copy to clipboard operation
websocket-sharp copied to clipboard

How to get client's ip when the connection opened

Open XxLittleCxX opened this issue 6 years ago • 3 comments

How to get client's ip when the connection opened

XxLittleCxX avatar Sep 15 '18 08:09 XxLittleCxX

protected override void OnOpen() { IPAddress clientIPAddress = Context.UserEndPoint.Address; }

frank12001 avatar Sep 18 '18 05:09 frank12001

My server is running on a machine behind a router. The router forwards packets based on the port to this machine.

Context.UserEndpoint.Address does have a valid IP address, but its the address of my router on the local network - not the IP of the client who actually made the request.

I've poked through the properties in the Context object and dont see anything obvious. Is there an way to get the original address of the requestor after the traffic has been port forwarded?

Robertsmania avatar Jun 21 '22 20:06 Robertsmania

Context.UserEndPoint.Address; is always 10.0.2.2 for me Even when creating server with new WebSocketServer(System.Net.IPAddress.Any, 3553);

UPD: it was the problem on my side, I'm sorry. Had to switch from NAT to Bridge Network in VirtualBox VM settings.

xtance avatar Dec 01 '23 21:12 xtance