// Clears static IP settings and enable DHCP private void DoSetDHCP() { string nicName = (string)comboBoxAdapters.SelectedItem; NetworkInterface nicSelected; FormMessagebox dlg = new FormMessagebox("Clear Static IP Settings (enable DHCP)", "Do you want to clear static IP settings for all network " + "adapters or only the selected one?", "Only the Selected (" + nicName + ")", "All Network Adapters", "Cancel"); dlg.ShowDialog(); if (dlg.ButtonPressed == 0 || dlg.ButtonPressed == 3) { return; } LogMessage("Clearing static IP settings and set back to DHCP"); ChangeStatus("Clearing static IP settings and set back to DHCP", 25); if (dlg.ButtonPressed == 1) { nicSelected = GetNic(nicName); EnableDHCP(nicSelected); LogMessage("Cleared static IP/DNS settings and set back to DHCP (" + nicName + ")"); } else if (dlg.ButtonPressed == 2) { NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces(); foreach (NetworkInterface nic in nics) { EnableDHCP(nic); } LogMessage("Cleared static IP/DNS settings and set back to DHCP (All Adapters)"); ChangeStatus("Ready", 0); } ChangeStatus("Ready", 0); }
private void DoGoogleDNS() { string nicName = (string)comboBoxAdapters.SelectedItem; FormMessagebox dlg = new FormMessagebox("Change to Emory DNS", "Do you want to set Emory DNS for all network " + "adapters or only the selected one?", "Only the Selected (" + nicName + ")", "All Network Adapters", "Cancel"); dlg.ShowDialog(); if (dlg.ButtonPressed == 0 || dlg.ButtonPressed == 3) { return; } LogMessage("Setting all DNS servers to Emory DNS"); ChangeStatus("Setting all DNS servers to Emory DNS", 25); if (dlg.ButtonPressed == 1) { RunCommand("netsh.exe", "interface ip set dns \"" + nicName + "\" static 170.140.2.1 primary"); RunCommand("netsh.exe", "interface ip add dns \"" + nicName + "\" 170.140.1.1 index=1"); LogMessage("Set DNS servers to Emory DNS (" + nicName + ")"); } else if (dlg.ButtonPressed == 2) { foreach (string adapter in GetAllAdapterNames()) { LogMessage("Setting DNS server for '" + adapter + "'"); ChangeStatus("Setting DNS server for '" + adapter + "'", 50); RunCommand("netsh.exe", "interface ip set dns \"" + adapter + "\" static 170.140.2.1 primary"); RunCommand("netsh.exe", "interface ip add dns \"" + adapter + "\" 170.140.1.1 index=1"); } LogMessage("Set DNS servers to Emory DNS (All Adapters)"); } ChangeStatus("Ready", 0); RefreshNetworkInfo(true); }