7

Is there anyone who knows how to get client IP address using socket programming while we are requesting the access of file transferring?? I am using C#.

2
  • 1
    Are you talking about getting the IP address(s) of the machine you are currently on, or the remote computer that is making a request? Commented Jul 23, 2010 at 13:40
  • basically i am developing a application for window mobile and we use xml files to store information in it. so when window mobile application make a request to save to save files in server than i want that my window application create a folder of that window mobile application and save all file in that folder. Commented Jul 26, 2010 at 12:39

3 Answers 3

8

In order to get the actual IP address:

// Using the RemoteEndPoint property.
Console.WriteLine (
"I am connected to " + IPAddress.Parse (((IPEndPoint)s.RemoteEndPoint).Address.ToString ()) + 
"on port number " + ((IPEndPoint)s.RemoteEndPoint).Port.ToString ());

// Using the LocalEndPoint property.
Console.WriteLine (
"My local IpAddress is :" + IPAddress.Parse (((IPEndPoint)s.LocalEndPoint).Address.ToString ()) +
"I am connected on port number " + ((IPEndPoint)s.LocalEndPoint).Port.ToString ());

taken from the msdn site:

Sign up to request clarification or add additional context in comments.

Comments

5

Socket.LocalEndPoint or Socket.RemoteEndPoint should do the trick, depending on whether you're the client or not.

Comments

0

Assuming you have a TcpListener, after the AcceptSocket call you are returned a Socket. On this socket you can call RemoteEndPoint

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.