diff --git a/FastGithub.Dns/FastGithub.Dns.csproj b/FastGithub.Dns/FastGithub.Dns.csproj
index 2300b43..ea1d4dc 100644
--- a/FastGithub.Dns/FastGithub.Dns.csproj
+++ b/FastGithub.Dns/FastGithub.Dns.csproj
@@ -7,7 +7,6 @@
-
diff --git a/FastGithub.Dns/SystemDnsUtil.cs b/FastGithub.Dns/SystemDnsUtil.cs
index 3595100..67a5cc2 100644
--- a/FastGithub.Dns/SystemDnsUtil.cs
+++ b/FastGithub.Dns/SystemDnsUtil.cs
@@ -1,8 +1,8 @@
using FastGithub.Configuration;
using System;
using System.Collections.Generic;
+using System.Diagnostics;
using System.Linq;
-using System.Management;
using System.Net;
using System.Net.NetworkInformation;
using System.Runtime.InteropServices;
@@ -94,23 +94,26 @@ namespace FastGithub.Dns
///
///
///
- ///
- private static bool SetNameServers(NetworkInterface @interface, IEnumerable nameServers)
+ private static void SetNameServers(NetworkInterface @interface, IEnumerable nameServers)
{
- var index = @interface.GetIPProperties().GetIPv4Properties().Index;
- using var wmi = new ManagementClass("Win32_NetworkAdapterConfiguration");
- foreach (ManagementObject adapter in wmi.GetInstances())
+ Netsh($@"interface ipv4 delete dns ""{@interface.Name}"" all");
+ foreach (var address in nameServers)
{
- if ((int)(uint)adapter["InterfaceIndex"] == index)
- {
- var inParams = adapter.GetMethodParameters("SetDNSServerSearchOrder");
- inParams["DNSServerSearchOrder"] = nameServers.Select(item => item.ToString()).ToArray();
- adapter.InvokeMethod("SetDNSServerSearchOrder", inParams, null);
- return true;
- }
+ Netsh($@"interface ipv4 add dns ""{@interface.Name}"" {address} validate=no");
}
- return false;
+ static void Netsh(string arguments)
+ {
+ var netsh = new ProcessStartInfo
+ {
+ FileName = "netsh.exe",
+ Arguments = arguments,
+ CreateNoWindow = true,
+ UseShellExecute = false,
+ WindowStyle = ProcessWindowStyle.Hidden
+ };
+ Process.Start(netsh)?.WaitForExit();
+ }
}
}
}
\ No newline at end of file