简体   繁体   中英

Get all clients which are connected to a remote server port

I want to get all clients which are connected to a server port (ie port 80).

If I connect to the remote port using:

IPEndPoint endPoint = new IPEndPoint(ip, port);
Socket tcpSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);  
tcpSocket.Connect(endPoint);  

I get as LocalEndPoint the ipaddress of the current client. How can I get the ip addresses of all clients which are connected to this port on the remote machine (or at least the count of connected clients)? I don't want to invoke the remote system.

Thanks for any help.

Harald

You can't. That's how sockets work and security is done. Once you have a connection between server and client, you can't get information about other clients.

You can change remote server code and alter protocol to add handling for your request so server will return number of connected clients. But that will require you to support that in protocol and alter TCP server implementation. Event that part can be tricky (calculate number of connected clients), because of half-closed connections, timeouts etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM