2010-07-23 117 views
3

有谁知道如何使用套接字编程获取客户端IP地址,而我们正在请求文件传输的访问?我正在使用C#。如何使用套接字编程获取客户端IP#

+1

你说的是获得本机的IP地址(S)你目前在,还是在发出请求的远程计算机上? – Josh 2010-07-23 13:40:37

+0

基本上我正在开发窗口移动应用程序,我们使用XML文件来存储信息。因此,当窗口移动应用程序发出请求以保存文件到服务器时,我希望我的窗口应用程序创建该窗口移动应用程序的文件夹并将所有文件保存在该文件夹中。 – 2010-07-26 12:39:29

回答

2

Socket.LocalEndPointSocket.RemoteEndPoint应该做的伎俩,取决于你是否是客户端。

2

为了得到实际的IP地址:

// 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()); 

msdn现场拍摄:

相关问题