public static int GetRandomPort()
{
var random = new Random();
var randomPort = random.Next(6000, 65535);
while (IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpListeners().Any(p => p.Port == randomPort))
{
randomPort = random.Next(6000, 65535);
}
return randomPort;
}
C# 获取随机可用端口号
最新推荐文章于 2024-03-30 15:47:48 发布