diff --git a/client/data/Methods/Network.cs b/client/data/Methods/Network.cs index 396afea..1b8bad0 100644 --- a/client/data/Methods/Network.cs +++ b/client/data/Methods/Network.cs @@ -4,10 +4,7 @@ using System.IO; using System.Linq; using System.Net; -using System.Net.NetworkInformation; using System.Runtime.InteropServices; -using System.Security.Cryptography; -using System.Text; using System.Threading.Tasks; namespace specify_client.data; @@ -37,7 +34,7 @@ public static async Task MakeNetworkData() NetAdapters = Utils.GetWmi("Win32_NetworkAdapterConfiguration", "Description, DHCPEnabled, DHCPServer, DNSDomain, DNSDomainSuffixSearchOrder, DNSHostName, " + "DNSServerSearchOrder, IPEnabled, IPAddress, IPSubnet, DHCPLeaseObtained, DHCPLeaseExpires, " - + "DefaultIPGateway, MACAddress, InterfaceIndex"); + + "DefaultIPGateway, MACAddress, InterfaceIndex, Index"); NetAdapters2 = Utils.GetWmi("MSFT_NetAdapter", "*", @@ -58,6 +55,7 @@ public static async Task MakeNetworkData() // This statement will avoid errors if the WMI value is not valid. ReceiveSideScaling = rcvSideScaling is not null && rcvSideScaling != 0; + await GetNetworkAdapterAdvancedConfig(); AutoTuningLevelLocal = GetAutoTuningLevels(); if (!Settings.RedactNetworking) @@ -343,6 +341,86 @@ public static string GetHostsFileHash() // If this catch happens, the error has already been reported in GetHostsFile() and does not need to be reported again. return ""; } - + + } + + private const string RegKeyNetworkAdapterAdvancedConfig = "SYSTEM\\CurrentControlSet\\Control\\Class\\{4d36e972-e325-11ce-bfc1-08002be10318}"; + + /// + /// Retrive network adapters configuration, set in "Advanced" tab in adapter's options. + /// + /// + public static async Task GetNetworkAdapterAdvancedConfig() + { + using RegistryKey subkey = Registry.LocalMachine.OpenSubKey(RegKeyNetworkAdapterAdvancedConfig); + if (subkey == null) + { + DebugLog.LogEvent($"Registry key for storing network adapters advanced configuration is missing!", DebugLog.Region.Networking, DebugLog.EventType.ERROR); + return; + } + foreach (var adapter in NetAdapters) + { + Dictionary netAdapterConfig = new(); + try + { + using RegistryKey adapterKey = subkey.OpenSubKey(((uint)adapter["Index"]).ToString("0000")); + if (adapterKey == null) + { + DebugLog.LogEvent($"Could not find advanced configuration for {adapter["Description"]}", DebugLog.Region.Networking, DebugLog.EventType.ERROR); + continue; + } + + using RegistryKey adapterParamsKey = adapterKey.OpenSubKey("NDI\\Params"); + if (adapterParamsKey == null) + { + //No advanced configuration options are available for the adapter. + continue; + } + + var parameterNames = adapterParamsKey.GetSubKeyNames(); + + foreach (string parameterName in parameterNames) + { + NetAdapterAdvancedParameter netAdapterParameter = new NetAdapterAdvancedParameter(); + netAdapterParameter.CurrentValue = adapterKey.GetValue(parameterName)?.ToString(); + + using RegistryKey parameterKey = adapterParamsKey.OpenSubKey($"{parameterName}"); + + if (parameterKey == null) + { + DebugLog.LogEvent($"Missing parameter definitions for {parameterName} for network adapter: {adapter["Description"]}", DebugLog.Region.Networking, DebugLog.EventType.WARNING); + continue; + } + + netAdapterParameter.Description = parameterKey.GetValue("ParamDesc")?.ToString(); + netAdapterParameter.DefaultValue = parameterKey.GetValue("default")?.ToString(); + netAdapterParameter.Type = parameterKey.GetValue("Type").ToString(); + + if (netAdapterParameter.Type.Equals("enum", StringComparison.OrdinalIgnoreCase)) + { + using RegistryKey parameterEnumsKey = parameterKey.OpenSubKey("Enum"); + + if (parameterEnumsKey == null) + { + DebugLog.LogEvent($"Missing enum definitions for {parameterName} for network adapter: {adapter["Description"]}", DebugLog.Region.Networking, DebugLog.EventType.WARNING); + continue; + } + + netAdapterParameter.PossibleEnumValues = parameterEnumsKey.GetValueNames() + .ToDictionary(x => x, x => parameterEnumsKey.GetValue(x)?.ToString()); + netAdapterParameter.CurrentValueName = netAdapterParameter.PossibleEnumValues[netAdapterParameter.CurrentValue]; + + } + netAdapterConfig.Add(parameterName, netAdapterParameter); + } + + adapter.Add("AdvancedConfiguration", netAdapterConfig); + } + catch (Exception e) + { + DebugLog.LogEvent($"Failed to read advanced configuration for network adapter: {adapter["Description"]}", DebugLog.Region.Networking, DebugLog.EventType.ERROR); + DebugLog.LogEvent($"{e}", DebugLog.Region.Networking, DebugLog.EventType.ERROR); + } + } } } \ No newline at end of file diff --git a/client/data/Structs.cs b/client/data/Structs.cs index 88d894a..b4d636a 100644 --- a/client/data/Structs.cs +++ b/client/data/Structs.cs @@ -18,6 +18,16 @@ public class NetworkRoute public List PacketLoss = new List(); } +public class NetAdapterAdvancedParameter +{ + public string Description { get; set; } + public string Type { get; set; } + public string DefaultValue { get; set; } + public string CurrentValue { get; set; } + public string CurrentValueName { get; set; } + public Dictionary PossibleEnumValues { get; set; } +} + public class InstalledApp { public string Name;