Reputation: 4875
For the purposes of constructing a rate limiter I need to be able to distinguish different users being routed through the same gateway. So if I have 100 clients with the same IP address I would like to tell them apart by what port they are associated with on the remote gateway/host/router.
I can get the IP easily with:
string clientIPAddress = ((IPEndPoint)tcpClient.Client.RemoteEndPoint).Address.ToString();
Is there some way similarly to get the remote port number for the client? Thanks.
Upvotes: 4
Views: 19204
Reputation: 6336
var port = ((IPEndPoint)tcpClient.Client.RemoteEndPoint).Port
Ref.: http://msdn.microsoft.com/en-us/library/system.net.ipendpoint.port.aspx
HTH.
Upvotes: 23