Пример #1
0
        public bool IsPortListening(int port)
        {
            if (_runtime.IsWindowsLinux || _ipGlobalProperties == null) // IPGlobalProperties is not implemented for WSL at this time
            {
                string netstat = _runtime.IsWindows || _runtime.IsWindowsLinux ? "netstat.exe" : "netstat";

                ProcessUtility.RunProcessAndWaitForExit(netstat, "-tna", _fileSystem, out string output, out string _, 5_000);

                return(ContainsNetstatPort(output, port));
            }

            var activeTcpPorts = _ipGlobalProperties.GetActiveTcpListeners();

            return(activeTcpPorts.Any(p => p.Port == port));
        }