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.2k times
6
-
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
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:

Zapnologica
- 22,170
- 44
- 158
- 253
5
Socket.LocalEndPoint
or Socket.RemoteEndPoint
should do the trick, depending on whether you're the client or not.

Stephen Cleary
- 437,863
- 77
- 675
- 810
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
- 339,232
- 124
- 596
- 636