SystemTrayApp: Added check for first run call to detect existing network DNS and ask user before changing the network DNS.

This commit is contained in:
Shreyas Zare
2022-03-06 17:02:59 +05:30
parent 03985c82a4
commit d83d53f51b

View File

@@ -1,6 +1,6 @@
/*
Technitium DNS Server
Copyright (C) 2021 Shreyas Zare (shreyas@technitium.com)
Copyright (C) 2022 Shreyas Zare (shreyas@technitium.com)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -105,7 +105,34 @@ namespace DnsServerSystemTrayApp
break;
case "--first-run":
bool usingLoopbackAsDns = false;
try
{
foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
{
if (nic.OperationalStatus != OperationalStatus.Up)
continue;
foreach (IPAddress dnsAddress in nic.GetIPProperties().DnsAddresses)
{
if (IPAddress.IsLoopback(dnsAddress))
{
usingLoopbackAsDns = true;
break;
}
}
if (usingLoopbackAsDns)
break;
}
}
catch
{ }
if (!usingLoopbackAsDns && MessageBox.Show("Do you want to update this computer's network connections to use the locally running Technitium DNS Server?\r\n\r\nNote! It is recommended that you use the locally running Technitium DNS Server unless you explicitly want to keep using your existing network DNS configuration.", "Switch Network DNS?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
SetNetworkDns(new DnsProvider("Technitium", new IPAddress[] { IPAddress.Loopback, IPAddress.IPv6Loopback }));
break;
}
}
@@ -294,7 +321,7 @@ namespace DnsServerSystemTrayApp
}
}
private void SetNetworkDns(DnsProvider dnsProvider)
private static void SetNetworkDns(DnsProvider dnsProvider)
{
if (!Program.IsAdmin)
{
@@ -446,7 +473,6 @@ namespace DnsServerSystemTrayApp
catch
{ }
NetworkDnsMenuItem.DropDownItems.Clear();
NetworkDnsMenuItem.DropDownItems.Add(DefaultNetworkDnsMenuItem);
NetworkDnsMenuItem.DropDownItems.Add(new ToolStripSeparator());