C#找出可用TCP端口,仅两行代码就搞定
var start = 2222; var ps = IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpListeners().Select(e => e.Port).Where(e => e > start).OrderBy(e => e).ToList(); var port = ps.Take(ps.Count - 1).Where((e, i) => ps[i + 1] - e > 1).FirstOrDefault();