public void OneClick() { setStatus("Set default DNS to google's DNS..."); HightLevelNetworkControll.setGoogleDNS(); setStatus("Getting hosts file data..."); string WriteData = HostFile.ReadDataWithoughtanstring("facebook") + Environment.NewLine; setStatus("Resolving IP Address..."); WriteData += HightLevelNetworkControll.ResolvedData(); setStatus("Restoring default DNS..."); HightLevelNetworkControll.RestoreDNS(); setStatus("Writing data to hosts file..."); HostFile.WriteHostData(WriteData); }
public void another(string address) { string buff = string.Empty; HightLevelNetworkControll.setGoogleDNS(); try { // phân giải được thì chép nó vào data buff = Dns.GetHostAddresses(address)[0].ToString() + " " + address; Dispatcher.BeginInvoke(new Action(delegate() { textboxresult.Text = buff; })); } catch {// không phân giải được thì báo là ko phân giải được Dispatcher.BeginInvoke(new Action(delegate() { textboxresult.Text = "Cant' resolve this host"; })); } HightLevelNetworkControll.RestoreDNS(); }
private void Button_Click(object sender, RoutedEventArgs e) { HightLevelNetworkControll.WriteThing += HightLevelNetworkControll_WriteThing; button.IsEnabled = false; progressbar.Visibility = Visibility.Visible; Listbox.Items.Clear(); new Thread(new ThreadStart(delegate() { try { OneClick(); setStatus("Resolve operation successfull"); } catch { setStatus("Operation fail, check the log below to find the problem!"); HightLevelNetworkControll.RestoreDNS(); } Dispatcher.BeginInvoke(new Action(delegate() { progressbar.Visibility = Visibility.Hidden; button.IsEnabled = true; })); HightLevelNetworkControll.WriteThing -= HightLevelNetworkControll_WriteThing; })).Start(); }