开发者

C#, how do i get an ip address, from a TcpClient?

C#, how do i get an ip address, from a TcpClient?

I have a T开发者_Python百科cpClient and i want to get it's name.


Assuming you want the remote end point:

IPEndPoint ipep = (IPEndPoint)myTcpClient.RemoteEndPoint;
IPAddress ipa = ipep.Address;


Say you have a TcpClient instance called MyTcpClient.

private string IPAddress
{
    get
    {
        IPEndPoint ep = MyTcpClient.Client.RemoteEndPoint as IPEndPoint;
        if (ep == null)
            return "unknown";
        return ep.Address.ToString();
    }
}


In case what you need is the local address instead you can use LocalEndPoint instead of RemoteEndPoimt in the previous replies.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜