diff --git a/InternetTest/InternetTest/Classes/Global.cs b/InternetTest/InternetTest/Classes/Global.cs index 8a7ce43..32d5666 100644 --- a/InternetTest/InternetTest/Classes/Global.cs +++ b/InternetTest/InternetTest/Classes/Global.cs @@ -30,6 +30,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE using Synethia; using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Net.Http; using System.Net.NetworkInformation; @@ -635,4 +636,40 @@ public static string GetCurrentWifiSSID() return null; } + public static async Task GetDnsCache() + { + // The PowerShell command to execute + string psCommand = "Get-DnsClientCache | ConvertTo-Json -Depth 4"; + + // Capture the JSON output asynchronously + string json = await RunPowerShellCommandAsync(psCommand); + return DnsCacheInfo.FromJson(json); + } + + public static async Task RunPowerShellCommandAsync(string psCommand) + { + // Create a new process to run PowerShell + ProcessStartInfo processInfo = new ProcessStartInfo + { + FileName = "powershell.exe", + Arguments = $"-Command \"{psCommand}\"", + RedirectStandardOutput = true, + RedirectStandardError = true, + UseShellExecute = false, + CreateNoWindow = true + }; + + // Start the PowerShell process + using Process process = Process.Start(processInfo); + + // Asynchronously read the output from the process + string output = await process.StandardOutput.ReadToEndAsync(); + + // Wait for the process to complete asynchronously + await process.WaitForExitAsync(); + + // Return the JSON output + return output; + } + } \ No newline at end of file diff --git a/InternetTest/InternetTest/Pages/DnsPage.xaml b/InternetTest/InternetTest/Pages/DnsPage.xaml index f76b563..18d8c64 100644 --- a/InternetTest/InternetTest/Pages/DnsPage.xaml +++ b/InternetTest/InternetTest/Pages/DnsPage.xaml @@ -325,7 +325,89 @@ - + + + + + +