You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
837 B

using System.Net.Sockets;
namespace EC.Util.Common;
public static class NetworkUtil
{
public static string LocalAddr(this TcpClient client)
{
return client.Client.LocalEndPoint?.ToString() ?? ":";
}
public static string LocalIp(this TcpClient client)
{
return LocalAddr(client).Split(':')[0];
}
public static string LocalPort(this TcpClient client)
{
return LocalAddr(client).Split(':')[1];
}
public static string ClientAddr(this TcpClient client)
{
return client.Client.RemoteEndPoint?.ToString() ?? ":";
}
public static string ClientIp(this TcpClient client)
{
return ClientAddr(client).Split(':')[0];
}
public static string ClientPort(this TcpClient client)
{
return ClientAddr(client).Split(':')[1];
}
}