tags:

views:

409

answers:

2

How to find out Connected Clients Ip Address. And how we can store that address to an array of datatype IPAddress?

A: 

Are we in Windows? Do you need to use this information inside an application or a console command could do the trick?

maybe you could try with netstat -na in a shell.

Jonathan
sorry i didn't get it...
Dilse Naaz
+1  A: 

Check the RemoteEndPoint of your socket:

If you are using a connection-oriented protocol, the RemoteEndPoint property gets the EndPoint that contains the remote IP address and port number to which the Socket is connected. If you are using a connectionless protocol, RemoteEndPoint contains the default remote IP address and port number with which the Socket will communicate. You must cast this EndPoint to an IPEndPoint before retrieving any information. You can then call the IPEndPoint.Address method to retrieve the remote IPAddress, and the IPEndPoint.Port method to retrieve the remote port number.

If you use higher level components like TcpListener and TcpClient then you can access the underlying socket and retrieve the remote end point.

If you use other technologies like ASP.Net, WCF or Remoting then you must say so in your post.

To store an IPAddress you retrieve the underlying bytes using IPAddress.GetAddressBytes. You reconstruct the address from the bytes using the byte[] constructor.

Remus Rusanu