[英]how to get client IP using socket programming c#
Is there anyone who knows how to get client IP address using socket programming while we are requesting the access of file transferring?? 当我们请求访问文件传输时,是否有人知道如何使用套接字编程获取客户端IP地址? I am using C#.
我正在使用C#。
Socket.LocalEndPoint
或Socket.RemoteEndPoint
应该可以解决问题,具体取决于您是否是客户端。
In order to get the actual IP address: 为了获得实际的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 ());
Assuming you have a TcpListener
, after the AcceptSocket
call you are returned a Socket
. 假设您有一个
TcpListener
,在AcceptSocket
调用之后返回一个Socket
。 On this socket you can call RemoteEndPoint
在此套接字上,您可以调用
RemoteEndPoint
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.