Extracting IP Address - C#

  • Thread starter Thread starter Tom Rahav
  • Start date Start date
T

Tom Rahav

Hello All,

I use .AcceptTcpClient method of a TcpListener object. My question is how
can I extract the IP address of the client that was accepted by the server?

Thanks!
Tom.
 
Hi Tom,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to get the client IP address
in AcceptTcpClient method. If there is any misunderstanding, please feel
free to let me know.

As far as I know, AcceptTcpClient method returns a TcpClient object. This
object didn't expose a method for us to get the endpoint. However, there is
a protected property Client, which you can use Reflection to get. To obtain
more flexibility, I suggest you use AcceptSocket method, which returns a
Socket object. You will get the IP address using LocalEndPoint directly.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Back
Top