public static void Main(string[] args) { try { var isLinux = RuntimeInformation.IsOSPlatform(OSPlatform.Linux); var isOSX = RuntimeInformation.IsOSPlatform(OSPlatform.OSX); var isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); IsColorEnabled = TryEnableConsoleColor(); ColorConsole.SetForeground(0x40, 0x80, 0x20); Value("Tool Version", typeof(Tool).Assembly.GetName().Version.ToString()); Header("Machine"); Value("Architecture", RuntimeInformation.ProcessArchitecture.ToString()); Value("Runtime Version", RuntimeEnvironment.GetSystemVersion()); Value("MachineName", Environment.MachineName); var os = isWindows ? "Windows" : isLinux ? "Linux" : isOSX ? "OSX" : "Other"; Value("OS", os); Value("OSVersion", Environment.OSVersion.ToString()); Value("ProcessorCount", Environment.ProcessorCount.ToString()); Value("SystemPageSize", Environment.SystemPageSize.ToString()); var tickCount = Environment.TickCount; Value("SystemStarted", DateTime.Now.AddMilliseconds(-Environment.TickCount).ToString() + " (local)"); Value("SystemUpTime", TimeSpan.FromMilliseconds(tickCount).ToString()); Header("Special Folders"); var specialFolders = Enum.GetNames(typeof(Environment.SpecialFolder)) .Zip(Enum.GetValues(typeof(Environment.SpecialFolder)).Cast <Environment.SpecialFolder>(), (name, value) => new { Name = name, Path = Environment.GetFolderPath(value, Environment.SpecialFolderOption.DoNotVerify), }) .OrderBy(sf => sf.Name, StringComparer.OrdinalIgnoreCase) .ToArray(); var maxSpecialFolderNameWith = specialFolders.Max(sf => sf.Name.Length); foreach (var specialFolder in specialFolders) { Value(specialFolder.Name, specialFolder.Path, maxSpecialFolderNameWith); } Header("Storage"); var drives = System.IO.DriveInfo.GetDrives(); bool first = true; foreach (var drive in drives) { if (first) { first = false; } else { Console.WriteLine(); } Value("Name", drive.Name); Value("Type", drive.DriveType.ToString()); Value("IsReady", drive.IsReady.ToString()); if (drive.IsReady) { try { Value("Label", drive.VolumeLabel); Value("Format", drive.DriveFormat ?? "Unknown"); Value("Size", FormatSize(drive.TotalSize)); Value("Free", FormatSize(drive.AvailableFreeSpace)); } catch { } } } Header("Time"); Value("UTC Time", DateTime.UtcNow.ToString()); Value("Local Time", DateTime.Now.ToString()); Value("TimeZone", TimeZoneInfo.Local.StandardName); Header("Region/Culture"); Value("Region", RegionInfo.CurrentRegion.Name); Value("Culture", CultureInfo.CurrentCulture.Name); Value("UICulture", CultureInfo.CurrentUICulture.Name); Header("User"); Value("Domain", Environment.UserDomainName); Value("User", Environment.UserName); Header("Network"); first = true; foreach (var net in NetworkInterface.GetAllNetworkInterfaces()) { if (net.OperationalStatus == OperationalStatus.Up && net.NetworkInterfaceType != NetworkInterfaceType.Loopback) { if (first) { first = false; } else { Console.WriteLine(); } Value("Type", net.NetworkInterfaceType.ToString()); Value("Description", net.Description); var props = net.GetIPProperties(); foreach (var addr in props.UnicastAddresses) { Value(addr.Address.AddressFamily.ToString(), addr.Address.ToString()); } } } Header("Environment"); foreach (var kvp in Environment.GetEnvironmentVariables().Cast <DictionaryEntry>().OrderBy(kvp => kvp.Key)) { var key = (string)kvp.Key; var value = (string)kvp.Value; if (StringComparer.OrdinalIgnoreCase.Equals(key, "LS_COLORS")) { LSColors(key, value); } else { if (SplitEnvVars.Contains(key)) { var separator = isWindows ? ';' : ':'; var values = value.Split(separator); Value(key, values, EnvVarWidth); } else { Value(key, value, EnvVarWidth); } } } } finally { // ensure restore the original settings on exit ColorConsole.SetDefaults(); } }
public static void Main() { using var trm = new ColorConsole(); var iw = new InfoWriter(trm); var isLinux = RuntimeInformation.IsOSPlatform(OSPlatform.Linux); var isOSX = RuntimeInformation.IsOSPlatform(OSPlatform.OSX); var isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); iw.Value("Tool Version", typeof(SystemInfoTool).Assembly.GetName().Version.ToString()); iw.Header("Machine"); iw.Value("Architecture", RuntimeInformation.ProcessArchitecture.ToString()); iw.Value("Runtime Version", RuntimeEnvironment.GetSystemVersion()); iw.Value("MachineName", Environment.MachineName); var os = isWindows ? "Windows" : isLinux ? "Linux" : isOSX ? "OSX" : "Other"; iw.Value("OS", os); iw.Value("OSVersion", Environment.OSVersion.ToString()); iw.Value("ProcessorCount", Environment.ProcessorCount.ToString()); iw.Value("SystemPageSize", Environment.SystemPageSize.ToString()); iw.Value("OSPlatform", Environment.Is64BitOperatingSystem ? "64" : "32"); var tickCount = Environment.TickCount64; iw.Value("SystemStarted", DateTime.Now.AddMilliseconds(-tickCount).ToString(DateFormat) + " (local)"); iw.Value("SystemUpTime", TimeSpan.FromMilliseconds(tickCount).ToString(@"d\.hh\:mm\:ss\.fff")); iw.Header("Memory"); var mi = Memory.GetMemoryInfo(); if (mi != null) { iw.Value("Total", FormatSize(mi.Total)); iw.Value("Available", FormatSize(mi.Available)); } else { iw.Value("Total", "unknown"); iw.Value("Available", "unknown"); } iw.Header("Storage"); var drives = DriveInfo.GetDrives(); bool first = true; foreach (var drive in drives.Where(d => d.DriveType == DriveType.Fixed)) { if (first) { first = false; } else { Console.WriteLine(); } iw.Value("Name", drive.Name); iw.Value("Type", drive.DriveType.ToString()); iw.Value("IsReady", drive.IsReady.ToString()); if (drive.IsReady) { try { iw.Value("Label", drive.VolumeLabel); iw.Value("Format", drive.DriveFormat ?? "Unknown"); iw.Value("Size", FormatSize(drive.TotalSize)); iw.Value("Free", FormatSize(drive.AvailableFreeSpace)); } catch { } } } iw.Header("Special Folders"); var specialFolders = Enum.GetNames(typeof(Environment.SpecialFolder)) .Zip(Enum.GetValues(typeof(Environment.SpecialFolder)).Cast <Environment.SpecialFolder>(), (name, value) => new { Name = name, Path = Environment.GetFolderPath(value, Environment.SpecialFolderOption.DoNotVerify), }) .Where(sf => !string.IsNullOrEmpty(sf.Path)) .OrderBy(sf => sf.Name, StringComparer.OrdinalIgnoreCase) .ToArray(); var maxSpecialFolderNameWith = specialFolders.Max(sf => sf.Name.Length) + 1; foreach (var specialFolder in specialFolders) { iw.Value(specialFolder.Name, specialFolder.Path, maxSpecialFolderNameWith); } iw.Header("Time"); iw.Value("UTC Time", DateTime.UtcNow.ToString(DateFormat) + " (UTC)"); iw.Value("Local Time", DateTime.Now.ToString(DateFormat) + " (local)"); iw.Value("TimeZone", TimeZoneInfo.Local.StandardName); iw.Header("Region/Culture"); iw.Value("Region", RegionInfo.CurrentRegion.Name); iw.Value("Culture", CultureInfo.CurrentCulture.Name); iw.Value("UICulture", CultureInfo.CurrentUICulture.Name); iw.Header("User"); iw.Value("Domain", Environment.UserDomainName); iw.Value("User", Environment.UserName); iw.Header("Network"); first = true; foreach (var net in NetworkInterface.GetAllNetworkInterfaces()) { if (net.OperationalStatus == OperationalStatus.Up && net.NetworkInterfaceType != NetworkInterfaceType.Loopback) { if (first) { first = false; } else { Console.WriteLine(); } iw.Value("Type", net.NetworkInterfaceType.ToString()); iw.Value("Description", net.Description); var props = net.GetIPProperties(); foreach (var addr in props.UnicastAddresses) { iw.Value(addr.Address.AddressFamily.ToString(), addr.Address.ToString()); } } } iw.Header("Environment"); foreach (var kvp in Environment.GetEnvironmentVariables().Cast <DictionaryEntry>().OrderBy(kvp => kvp.Key)) { var key = (string)kvp.Key; var value = (string)kvp.Value; if (StringComparer.OrdinalIgnoreCase.Equals(key, "LS_COLORS")) { LSColors(trm, iw, key, value); } else { if (SplitEnvVars.Contains(key)) { var separator = isWindows ? ';' : ':'; var values = value.Split(separator); iw.Value(key, values, EnvVarWidth); } else { iw.Value(key, value, EnvVarWidth); } } } }