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]; } }