mirror of
https://github.com/fergalmoran/DnsServer.git
synced 2025-12-22 09:29:50 +00:00
MainApplicationContext: added --first-run command line option to allow setting network dns to work with the local dns server after setup completes.
This commit is contained in:
@@ -103,6 +103,10 @@ namespace DnsServerSystemTrayApp
|
||||
case "--service-stop":
|
||||
StopServiceMenuItem_Click(this, EventArgs.Empty);
|
||||
break;
|
||||
|
||||
case "--first-run":
|
||||
SetNetworkDns(new DnsProvider("Technitium", new IPAddress[] { IPAddress.Loopback, IPAddress.IPv6Loopback }));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -290,6 +294,35 @@ namespace DnsServerSystemTrayApp
|
||||
}
|
||||
}
|
||||
|
||||
private void SetNetworkDns(DnsProvider dnsProvider)
|
||||
{
|
||||
if (!Program.IsAdmin)
|
||||
{
|
||||
Program.RunAsAdmin("--network-dns-item " + dnsProvider.Name);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
|
||||
{
|
||||
if (nic.OperationalStatus != OperationalStatus.Up)
|
||||
continue;
|
||||
|
||||
IPInterfaceProperties properties = nic.GetIPProperties();
|
||||
|
||||
if ((properties.DnsAddresses.Count > 0) && !properties.DnsAddresses[0].IsIPv6SiteLocal)
|
||||
SetNameServer(nic, dnsProvider.Addresses);
|
||||
}
|
||||
|
||||
MessageBox.Show("The network DNS servers were set to " + dnsProvider.Name + " successfully.", dnsProvider.Name + " Configured - " + Resources.ServiceName, MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Error occured while setting " + dnsProvider.Name + " as network DNS server. " + ex.Message, "Error - " + Resources.ServiceName, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private static void SetNameServer(NetworkInterface nic, ICollection<IPAddress> dnsAddresses)
|
||||
{
|
||||
SetNameServerIPv4(nic, dnsAddresses);
|
||||
@@ -627,31 +660,7 @@ namespace DnsServerSystemTrayApp
|
||||
ToolStripMenuItem item = sender as ToolStripMenuItem;
|
||||
DnsProvider dnsProvider = item.Tag as DnsProvider;
|
||||
|
||||
if (!Program.IsAdmin)
|
||||
{
|
||||
Program.RunAsAdmin("--network-dns-item " + dnsProvider.Name);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
|
||||
{
|
||||
if (nic.OperationalStatus != OperationalStatus.Up)
|
||||
continue;
|
||||
|
||||
IPInterfaceProperties properties = nic.GetIPProperties();
|
||||
|
||||
if ((properties.DnsAddresses.Count > 0) && !properties.DnsAddresses[0].IsIPv6SiteLocal)
|
||||
SetNameServer(nic, dnsProvider.Addresses);
|
||||
}
|
||||
|
||||
MessageBox.Show("The network DNS servers were set to " + dnsProvider.Name + " successfully.", dnsProvider.Name + " Configured - " + Resources.ServiceName, MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Error occured while setting " + dnsProvider.Name + " as network DNS server. " + ex.Message, "Error - " + Resources.ServiceName, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
SetNetworkDns(dnsProvider);
|
||||
}
|
||||
|
||||
private void StartServiceMenuItem_Click(object sender, EventArgs e)
|
||||
|
||||
Reference in New Issue
Block a user