Program.cs 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. Technitium DNS Server
  3. Copyright (C) 2024 Shreyas Zare (shreyas@technitium.com)
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. using DnsServerCore;
  16. using System;
  17. using System.Threading;
  18. namespace DnsServerApp
  19. {
  20. class Program
  21. {
  22. static void Main(string[] args)
  23. {
  24. string configFolder = null;
  25. if (args.Length == 1)
  26. configFolder = args[0];
  27. ManualResetEvent waitHandle = new ManualResetEvent(false);
  28. ManualResetEvent exitHandle = new ManualResetEvent(false);
  29. DnsWebService service = null;
  30. try
  31. {
  32. Uri updateCheckUri;
  33. switch (Environment.OSVersion.Platform)
  34. {
  35. case PlatformID.Win32NT:
  36. updateCheckUri = new Uri("https://go.technitium.com/?id=41");
  37. break;
  38. default:
  39. updateCheckUri = new Uri("https://go.technitium.com/?id=42");
  40. break;
  41. }
  42. service = new DnsWebService(configFolder, updateCheckUri, new Uri("https://go.technitium.com/?id=44"));
  43. service.Start();
  44. Console.CancelKeyPress += delegate (object sender, ConsoleCancelEventArgs e)
  45. {
  46. e.Cancel = true;
  47. waitHandle.Set();
  48. };
  49. AppDomain.CurrentDomain.ProcessExit += delegate (object sender, EventArgs e)
  50. {
  51. waitHandle.Set();
  52. exitHandle.WaitOne();
  53. };
  54. Console.WriteLine("Technitium DNS Server was started successfully.");
  55. Console.WriteLine("Using config folder: " + service.ConfigFolder);
  56. Console.WriteLine("");
  57. Console.WriteLine("Note: Open http://" + Environment.MachineName.ToLowerInvariant() + ":" + service.WebServiceHttpPort + "/ in web browser to access web console.");
  58. Console.WriteLine("");
  59. Console.WriteLine("Press [CTRL + C] to stop...");
  60. waitHandle.WaitOne();
  61. }
  62. catch (Exception ex)
  63. {
  64. Console.WriteLine(ex.ToString());
  65. }
  66. finally
  67. {
  68. Console.WriteLine("");
  69. Console.WriteLine("Technitium DNS Server is stopping...");
  70. if (service != null)
  71. service.Dispose();
  72. Console.WriteLine("Technitium DNS Server was stopped successfully.");
  73. exitHandle.Set();
  74. }
  75. }
  76. }
  77. }