!B (Sandbox) (CE-21795) Importing models with multisubmaterials via fbx switches...
[CRYENGINE.git] / Code / Tools / VisualStudioExtensions / CryEngineMonoDebugger / source / CryEngine.Debugger.Mono / NetworkHelper.cs
blobea13ef6e00c52a1704b942e7f974153169f2e849
1 // Copyright 2001-2019 Crytek GmbH / Crytek Group. All rights reserved.
3 using System;
4 using System.Linq;
5 using System.Net.NetworkInformation;
7 namespace CryEngine.Debugger.Mono
9 public static class NetworkHelper
11 public static int GetAvailablePort(int startPort, int stopPort)
13 var random = new Random(DateTime.Now.Millisecond);
15 IPGlobalProperties ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties();
16 TcpConnectionInformation[] tcpConnInfoArray = ipGlobalProperties.GetActiveTcpConnections();
18 var busyPorts = tcpConnInfoArray.Select(t => t.LocalEndPoint.Port).Where(v => v >= startPort && v <= stopPort).ToArray();
20 var firstAvailableRandomPort = Enumerable.Range(startPort, stopPort - startPort).OrderBy(v => random.Next()).FirstOrDefault(p => !busyPorts.Contains(p));
22 return firstAvailableRandomPort;