/// <summary>
/// Find free network port for Udp or Tcp client/server
/// </summary>
/// <param name="start">Port number to start scan</param>
/// <returns>Found free port number</returns>
static int FindFreeNetworkPort(int start) {
	if (start < 1 || start > 65535)
		return start;

	bool portUsed = true;
	while (portUsed) {

		var r1 = IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpListeners().Where(t => t.Port == start).Count();
		var r2 = IPGlobalProperties.GetIPGlobalProperties().GetActiveUdpListeners().Where(t => t.Port == start).Count();
		var r3 = IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpConnections().Where(t => t.LocalEndPoint.Port == start).Count();

		portUsed = (r1 > 0) | (r2 > 0) | (r3 > 0);
		if (portUsed) {
			if (start < 65535)
				start++;
			else
				break;

		}
        
	}
	return start;
}