检测端口是否使用
static bool CheckPortAvailable(int port) { bool isAvailable = true; IPGlobalProperties ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties(); foreach (var tcplisten in ipGlobalProperties.GetActiveTcpListeners()) { if (tcplisten.Port == port) { isAvailable = false; break; } } if (isAvailable) { foreach (var udplisten in ipGlobalProperties.GetActiveUdpListeners()) { if (udplisten.Port == port) { isAvailable = false; break; } } } return isAvailable; }