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#.
-
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– Josh2010-07-23 13:40:37 +00:00Commented 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.Emaad Ali– Emaad Ali2010-07-26 12:39:29 +00:00Commented Jul 26, 2010 at 12:39
Add a comment
|
3 Answers
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:
Comments
Assuming you have a TcpListener, after the AcceptSocket call you are returned a Socket. On this socket you can call RemoteEndPoint