Example #1
0
        public void Dispose()
        {
            var netsh = new NetShell();

            foreach (var x in originalDnsServers)
            {
                netsh.SetDnsServers(x.Key, x.Value);
            }
            netsh.Run();
        }
Example #2
0
        /// <summary>
        ///   Set the DNS server addresses for all network interfaces.
        /// </summary>
        /// <param name="server">
        ///   The sequence of <see cref="IPAddress"/> for the DNS server.
        /// </param>
        public void SetDnsServer(IEnumerable <IPAddress> addresses)
        {
            var netsh = new NetShell();
            var nics  = NetworkInterface
                        .GetAllNetworkInterfaces()
                        .Where(nic => nic.NetworkInterfaceType != NetworkInterfaceType.Loopback)
                        .Where(nic =>
                               nic.Supports(NetworkInterfaceComponent.IPv4) ||
                               nic.Supports(NetworkInterfaceComponent.IPv6));

            foreach (var nic in nics)
            {
                var original = nic.GetIPProperties().DnsAddresses;
                originalDnsServers[nic] = original;
                netsh.SetDnsServers(nic, addresses);
            }
            netsh.Run();
        }