33using System . ComponentModel ;
44using System . Data ;
55using System . Diagnostics ;
6+ using System . IO ;
67using System . Linq ;
78using System . Management ;
9+ using System . Net . Http ;
810using System . ServiceProcess ;
911using System . Text ;
1012using System . Threading . Tasks ;
@@ -15,6 +17,8 @@ namespace DnsOverride
1517 public partial class Service1 : ServiceBase
1618 {
1719 private Timer timer ;
20+ string hosts = Path . Combine ( Environment . SystemDirectory , @"drivers\etc\hosts" ) ;
21+ string url = "https://raw.githubusercontent.com/LasseTheBabo/files/master/hosts" ;
1822
1923 public Service1 ( )
2024 {
@@ -26,20 +30,31 @@ protected override void OnStart(string[] args)
2630 Log ( "DnsOverride gestartet." ) ;
2731
2832 timer = new Timer ( 60 * 1000 ) ;
29- timer . Elapsed += ( ( sernder , e ) => SetDns ( ) ) ;
33+ timer . Elapsed += async ( sender , e ) => await SetDns ( ) ;
34+
3035 timer . AutoReset = true ;
3136 timer . Start ( ) ;
3237
33- SetDns ( ) ;
38+ Task . Run ( ( ) => SetDns ( ) ) ;
3439 }
3540
3641 protected override void OnStop ( )
3742 {
3843 Log ( "DnsOverride gestoppt." ) ;
3944 }
4045
41- public void SetDns ( )
46+ public async Task SetDns ( )
4247 {
48+ using ( HttpClient client = new HttpClient ( ) )
49+ {
50+ try
51+ {
52+ string content = await client . GetStringAsync ( url ) ;
53+ File . WriteAllText ( hosts , content ) ;
54+ }
55+ catch { }
56+ }
57+
4358 try
4459 {
4560 string [ ] dns = { "1.1.1.3" } ;
@@ -69,7 +84,7 @@ public void SetDns()
6984 }
7085 }
7186
72- private static void Log ( string message )
87+ internal static void Log ( string message )
7388 {
7489 try
7590 {
0 commit comments