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#.
Asked
Active
Viewed 2.0k times
5
-
1Are you talking about getting the IP address(s) of the machine you are currently on, or the remote computer that is making a request? – Josh Jul 23 '10 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. – Emaad Ali Jul 26 '10 at 12:39
3 Answers
6
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:
Zapnologica
- 21,164
- 41
- 147
- 239
4
Socket.LocalEndPoint or Socket.RemoteEndPoint should do the trick, depending on whether you're the client or not.
Stephen Cleary
- 406,130
- 70
- 637
- 767
0
Assuming you have a TcpListener, after the AcceptSocket call you are returned a Socket. On this socket you can call RemoteEndPoint
Brian R. Bondy
- 327,498
- 120
- 583
- 623