2017-12-29 22:15:27 +05:30
/ *
Technitium DNS Server
2025-03-29 17:34:53 +05:30
Copyright ( C ) 2025 Shreyas Zare ( shreyas @technitium . com )
2017-12-29 22:15:27 +05:30
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
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program . If not , see < http : //www.gnu.org/licenses/>.
* /
using DnsServerCore ;
using System ;
2018-12-30 16:46:42 +05:30
using System.Threading ;
2017-12-29 22:15:27 +05:30
namespace DnsServerApp
{
class Program
{
static void Main ( string [ ] args )
{
string configFolder = null ;
if ( args . Length = = 1 )
2025-04-19 15:18:03 +05:30
{
if ( args [ 0 ] = = "--icu-test" )
{
_ = System . Globalization . CultureInfo . CurrentCulture ;
return ;
}
2017-12-29 22:15:27 +05:30
configFolder = args [ 0 ] ;
2025-04-19 15:18:03 +05:30
}
2017-12-29 22:15:27 +05:30
2024-09-14 16:26:13 +05:30
ManualResetEvent waitHandle = new ManualResetEvent ( false ) ;
ManualResetEvent exitHandle = new ManualResetEvent ( false ) ;
2021-03-06 17:58:14 +05:30
DnsWebService service = null ;
2017-12-29 22:15:27 +05:30
2018-12-30 16:46:42 +05:30
try
2017-12-29 22:15:27 +05:30
{
2020-12-26 17:33:32 +05:30
Uri updateCheckUri ;
switch ( Environment . OSVersion . Platform )
{
case PlatformID . Win32NT :
2021-10-02 13:17:37 +05:30
updateCheckUri = new Uri ( "https://go.technitium.com/?id=41" ) ;
2020-12-26 17:33:32 +05:30
break ;
default :
2021-10-02 13:17:37 +05:30
updateCheckUri = new Uri ( "https://go.technitium.com/?id=42" ) ;
2020-12-26 17:33:32 +05:30
break ;
}
2022-09-18 18:18:59 +05:30
service = new DnsWebService ( configFolder , updateCheckUri , new Uri ( "https://go.technitium.com/?id=44" ) ) ;
2018-12-30 16:46:42 +05:30
service . Start ( ) ;
2017-12-29 22:15:27 +05:30
2019-01-19 15:14:46 +05:30
Console . CancelKeyPress + = delegate ( object sender , ConsoleCancelEventArgs e )
2018-12-30 16:46:42 +05:30
{
2019-01-19 15:14:46 +05:30
e . Cancel = true ;
2020-06-06 18:13:01 +05:30
waitHandle . Set ( ) ;
2019-01-19 15:14:46 +05:30
} ;
2017-12-29 22:15:27 +05:30
2019-01-19 15:14:46 +05:30
AppDomain . CurrentDomain . ProcessExit + = delegate ( object sender , EventArgs e )
{
2020-06-06 18:13:01 +05:30
waitHandle . Set ( ) ;
exitHandle . WaitOne ( ) ;
2019-01-19 15:14:46 +05:30
} ;
2025-03-29 17:34:53 +05:30
Console . WriteLine ( "Technitium DNS Server was started successfully.\r\nUsing config folder: " + service . ConfigFolder + "\r\n\r\nNote: Open http://" + Environment . MachineName . ToLowerInvariant ( ) + ":" + service . WebServiceHttpPort + "/ in web browser to access web console.\r\n\r\nPress [CTRL + C] to stop..." ) ;
2020-06-06 18:13:01 +05:30
waitHandle . WaitOne ( ) ;
2018-12-30 16:46:42 +05:30
}
catch ( Exception ex )
{
Console . WriteLine ( ex . ToString ( ) ) ;
}
finally
{
2025-03-29 17:34:53 +05:30
Console . WriteLine ( "\r\nTechnitium DNS Server is stopping..." ) ;
2020-06-06 18:13:01 +05:30
2018-12-30 16:46:42 +05:30
if ( service ! = null )
service . Dispose ( ) ;
2020-06-06 18:13:01 +05:30
Console . WriteLine ( "Technitium DNS Server was stopped successfully." ) ;
exitHandle . Set ( ) ;
2018-12-30 16:46:42 +05:30
}
2017-12-29 22:15:27 +05:30
}
}
}