Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the IP Address of a Remote Socket Endpoint

How do I determine the remote IP Address of a connected socket?

I have a RemoteEndPoint object I can access and well as its AddressFamily member.

How do I utilize these to find the ip address?

Thanks!

Currently trying

IPAddress.Parse( testSocket.Address.Address.ToString() ).ToString(); 

and getting 1.0.0.127 instead of 127.0.0.1 for localhost end points. Is this normal?

like image 370
bobber205 Avatar asked Dec 14 '09 23:12

bobber205


People also ask

How do I find the endpoint of an IP?

The IP address is available in most locations the endpoint name is displayed, including lists and tool tips. In some lists, such as the Endpoint Diary, you can choose to view the Endpoint/Client Name or Endpoint/Client IP Address by clicking the toggle next to the column header.

What is remote EndPoint?

An endpoint is a remote computing device that communicates back and forth with a network to which it is connected. Examples of endpoints include: Desktops.

What is IP end point?

The IPEndPoint class contains the host and local or remote port information needed by an application to connect to a service on a host. By combining the host's IP address and port number of a service, the IPEndPoint class forms a connection point to a service.


1 Answers

http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.remoteendpoint.aspx

You can then call the IPEndPoint..::.Address method to retrieve the remote IPAddress, and the IPEndPoint..::.Port method to retrieve the remote port number.

More from the link (fixed up alot heh):

Socket s;          IPEndPoint remoteIpEndPoint = s.RemoteEndPoint as IPEndPoint; IPEndPoint localIpEndPoint = s.LocalEndPoint as IPEndPoint;  if (remoteIpEndPoint != null) {     // Using the RemoteEndPoint property.     Console.WriteLine("I am connected to " + remoteIpEndPoint.Address + " on port number " + remoteIpEndPoint.Port); }  if (localIpEndPoint != null) {     // Using the LocalEndPoint property.     Console.WriteLine("My local IpAddress is " + localIpEndPoint.Address + " connected on port number " + localIpEndPoint.Port); } 
like image 105
Cory Charlton Avatar answered Sep 22 '22 01:09

Cory Charlton