public void Apply(Profile p) { Dictionary <string, string> nics = NetworkManagement.getNetworkcardDescriptionAndMacAddresses(); if (nics.TryGetValue(p.MAC, out string n)) { if (p.DHCP) { NetworkManagement.enableDHCP(p.MAC); if (p.DNS.Count > 0) { foreach (var dns in p.DNS) { NetworkManagement.setDNS(p.MAC, dns.DomainServerIP); } } } else { NetworkManagement.setIP(p.MAC, p.IP); } } else { int yy = 0; } }
private void btnClearDns_Click(object sender, EventArgs e) { UpdateCurrentDNSLabelValues(new[] { "(Waiting)", "(Waiting)" }); NetworkManagement.SetNameservers(CurrentNic, null, restart: true); tbDns01.Text = tbDns02.Text = ""; RefreshDNSValues(); }
private string[] RefreshDNSValues() { var dnsServers = NetworkManagement.GetNameservers(CurrentNic); UpdateCurrentDNSLabelValues(dnsServers); return(dnsServers); }
/* //人物状态UI设置,包括护盾,冰冻,加速,中毒状态 * public Image shieldImage;//护盾状态 * public Image speedUpImage;//加速状态 * public Image poisonImage;//中毒状态 * public Image frozenImage;//冰冻状态 * //弓箭形态 * public Image ballArrowImage;//巨型弓箭 * public Image fireArrowImage;//火箭 * public Image poisonArrowImage;//毒箭 * public Image frozenArrowImage;//冰冻箭 * public Image splitArrowImage;//分裂箭 */ public override void OnStartLocalPlayer() { base.OnStartLocalPlayer(); player = this.gameObject; GameObject.Find("Camera").GetComponent <CameraFollow>().player = this.gameObject; hp = player.transform.Find("Canvas_HP").GetComponent <Canvas>(); hp.worldCamera = GameObject.Find("Camera").GetComponent <Camera>(); //设置人物血条的相机 gameController = GameObject.Find("GameController").GetComponent <GameController>(); if (this.gameObject.tag == "TeamBlue") { gameController.teamtype = true; gameController.StartPosition = GameObject.Find("BlueSpawn"); } else { gameController.teamtype = false; gameController.StartPosition = GameObject.Find("RedSpawn"); } networkManagement = GameObject.Find("NetworkManager").GetComponent <NetworkManagement>(); teamtype = GameObject.Find("GameController").GetComponent <GameController>().teamtype; if (teamtype) { //blue //playerPrefab = networkManagement.spawnPrefabs.Find(prefab => prefab.name == "Hunter_BLUE"); playerRespawnPos = networkManagement.blueStartPosition; } else { //playerPrefab = networkManagement.spawnPrefabs.Find(prefab => prefab.name == "Hunter_RED"); playerRespawnPos = networkManagement.redStartPosition; } }
private static void ShowNicNames() { int i = 1; foreach (var x in NetworkInterface.GetAllNetworkInterfaces().ToList()) { Console.WriteLine(i++ + ". " + x.Description + " : " + x.Name + " : " + x.OperationalStatus); Console.WriteLine( " IP Address: .....................................: " + NetworkUtils.GetIpFromAdaptorDesc(x.Description)); Console.WriteLine( " DHCP Enabled.....................................: " + !NetworkManagement.IsNetworkedWithStaticIp(x.Description)); Console.WriteLine(); } }
public static void Bulid() { NetworkManagement = new NetworkManagement(); PingChecker = new PingChecker(); ProcessManager = new ProcessManager(); var customSection = ConfigurationManager.GetSection("CommandsSettings") as CommandsSection; List <string> processes = new List <string>(); for (int i = 0; i < customSection.Command.Count; i++) { processes.Add(customSection.Command[i].value); } Commands = processes; }
private void MainForm_Load(object sender, EventArgs e) { // Append the version number to the form title var version = typeof(MainForm).Assembly.GetName().Version; if (version != null) { this.Text += $" | v{version}"; } // Load the DNS server config from the file ReloadContextMenuItems(); // Get all the nics and load them into a drop down, // if we have any NICs, fill dropdown and // select the first one from the list as current. var nics = NetworkManagement.GetAllNicDescriptions(); cmbNics.Items.AddRange(nics.Length > 0 ? nics : new string[] { "No Available NiCs" }); cmbNics.SelectedIndex = 0; }
private void btnApplyDns_Click(object sender, EventArgs e) { string dns01 = tbDns01.Text?.Trim(); if (!string.IsNullOrWhiteSpace(dns01) && !IsValidIPv4(dns01)) { MessageBox.Show(this, "DNS 1 is not a valid IPv4 address", "Invalid IPv4", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } string dns02 = tbDns02.Text?.Trim(); if (!string.IsNullOrWhiteSpace(dns02) && !IsValidIPv4(dns02)) { MessageBox.Show(this, "DNS 2 is not a valid IPv4 address", "Invalid IPv4", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } UpdateCurrentDNSLabelValues(new[] { "(Waiting)", "(Waiting)" }); NetworkManagement.SetNameservers(CurrentNic, new[] { dns01, dns02 }, restart: true); RefreshDNSValues(); }
private void Config() { ProgressBarPerform = new KeyValuePair<bool, int>(true, 100); //прочитаем из реестра guid последнего использованого адаптера, если такового нет оставим пустое и будем ждать пока пользователь выберет на комбобоксе нужный string adaptGUID = String.Empty; try { adaptGUID = (string)RegistryWorker.GetKeyValue<string>(Microsoft.Win32.RegistryHive.LocalMachine, VentsConst._SETTINGSLOCATION, VentsConst._LASTADPTGUID); } catch (System.IO.IOException) { } catch (Exception ex) { _log.Error(ex.Message + " (чтение из реестра)"); VentsTools.currentSettingString = "Ошибка чтения реестра"; } if (adaptGUID == String.Empty) { VentsTools.currentSettingString = "Выберите сетевой адаптер"; Dispatcher.Invoke(new Action(() => comboBoxAdapters.SelectionChanged += new SelectionChangedEventHandler(comboBoxAdapters_SelectedIndexChangedSuspended))); _cfgthread.Suspend(); Dispatcher.Invoke(new Action(() => comboBoxAdapters.SelectionChanged -= new SelectionChangedEventHandler(comboBoxAdapters_SelectedIndexChangedSuspended))); } else { int index = 0; foreach (NetworkAdapters adp in comboBoxAdapters.ItemsSource) { if (adaptGUID == adp.GUID) { Dispatcher.Invoke(new Action(() => comboBoxAdapters.SelectedIndex = index)); break; } index++; } if ((bool)Dispatcher.Invoke(new Func<bool>(() => comboBoxAdapters.SelectedIndex == -1))) { _log.Info(String.Format("Сетевой адаптер GUID={0} недоступен", adaptGUID)); VentsTools.currentSettingString = "Последний использованный адаптер недоступен, выберите другой"; VentsTools.currentSettingString = "Выберите сетевой адаптер"; Dispatcher.Invoke(new Action(() => comboBoxAdapters.SelectionChanged += new SelectionChangedEventHandler(comboBoxAdapters_SelectedIndexChangedSuspended))); _cfgthread.Suspend(); Dispatcher.Invoke(new Action(() => comboBoxAdapters.SelectionChanged -= new SelectionChangedEventHandler(comboBoxAdapters_SelectedIndexChangedSuspended))); } } Vips = GetIPSettings((string)Dispatcher.Invoke(new Func<string>(() => (comboBoxAdapters.SelectedItem as NetworkAdapters).GUID))); bool state1 = false; bool state2 = false; bool state3 = false; NetworkManagement NM = new NetworkManagement(); //Получим текущие настройки на машине, для wincos network запишем дефолтные try { if (Vips.belsIP == null) Vips.belsIP = NM.GetIP(ref state1, (string)Dispatcher.Invoke(new Func<string>(() => (comboBoxAdapters.SelectedItem as NetworkAdapters).AdapterDescriptionFull)))[0]; if (Vips.belsMask == null) Vips.belsMask = NM.GetSubnetMask(ref state2, (string)Dispatcher.Invoke(new Func<string>(() => (comboBoxAdapters.SelectedItem as NetworkAdapters).AdapterDescriptionFull)))[0]; if (Vips.belsGate == null) Vips.belsGate = NM.GetGateway(ref state3, (string)Dispatcher.Invoke(new Func<string>(() => (comboBoxAdapters.SelectedItem as NetworkAdapters).AdapterDescriptionFull)))[0]; if (Vips.wincIP == null) Vips.wincIP = VentsConst._DEFAULTWINCOSIP; if (Vips.wincMask == null) Vips.wincMask = VentsConst._DEFAULTWINCOSMASK; if (Vips.wincGate == null) Vips.wincGate = VentsConst._DEFAULTWINCOSGATEWAY; } catch (Exception ex) { _log.Error(ex); } Dispatcher.Invoke(new Action(() => { belsIPadr.IsEnabled = true; belsMask.IsEnabled = true; belsGate.IsEnabled = true; wincIPadr.IsEnabled = true; wincMask.IsEnabled = true; wincGate.IsEnabled = true; applyBelsbutt.IsEnabled = true; applyWincbutt.IsEnabled = true; })); //загрузим последнюю нажатую кнопку string applyButtonClicked = String.Empty; try { applyButtonClicked = RegistryWorker.GetKeyValue<string>(Microsoft.Win32.RegistryHive.LocalMachine, VentsConst._SETTINGSLOCATION, VentsConst._LASTAPPLYBUTTONCLICKED); } catch (System.IO.IOException) { } catch (Exception ex) { _log.Error(ex.Message + " (чтение из реестра)"); VentsTools.currentSettingString = "Ошибка чтения реестра"; } if (applyButtonClicked == "BELSOLOD") Dispatcher.Invoke(new Action(() => { belsRect.Stroke = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFE8F5FC")); belsRect.Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFE8F5FC")); })); else if (applyButtonClicked == "WINCOS") Dispatcher.Invoke(new Action(() => { wincRect.Stroke = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFE8F5FC")); wincRect.Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFE8F5FC")); })); else { VentsTools.currentSettingString = "Выберите сеть для работы"; ProgressBarPerform = new KeyValuePair<bool, int>(false, 100); return; } VentsTools.currentSettingString = String.Format("Последние использованые настройки: {0}", applyButtonClicked == "BELSOLOD" ? "Сеть Белсолод" : "Сеть Wincos"); ProgressBarPerform = new KeyValuePair<bool, int>(false, 100); }
private void ApplyWincos() { ProgressBarPerform = new KeyValuePair<bool, int>(true, 100); if ((object)Dispatcher.Invoke(new Func<object>(() => { return comboBoxAdapters.SelectedValue; })) != null) { NetworkManagement NM = new NetworkManagement(); try { bool ipmark = false; bool gatemark = false; bool netbiosmark = true; //Проверим Netbios, если не равен DISABLED, то выключим if (NM.GetTcpipNetbiosState((string)Dispatcher.Invoke(new Func<string>(() => (comboBoxAdapters.SelectedItem as NetworkAdapters).AdapterDescriptionFull))) != 2) netbiosmark = NM.SetTcpipNetbios(2, (string)Dispatcher.Invoke(new Func<string>(() => (comboBoxAdapters.SelectedItem as NetworkAdapters).AdapterDescriptionFull))); ipmark = NM.SetIP(Vips.wincIP, Vips.wincMask, (string)Dispatcher.Invoke(new Func<string>(() => (comboBoxAdapters.SelectedItem as NetworkAdapters).AdapterDescriptionFull))); // Thread.Sleep(3000); if (!ipmark) { _log.Error(String.Format("Не удалось изменить параметры сети IP={0}, mask={1}, adaperName={2}, adapterGuid={3}", Vips.wincIP, Vips.wincMask, (string)Dispatcher.Invoke(new Func<string>(() => (comboBoxAdapters.SelectedItem as NetworkAdapters).AdapterDescriptionFull)), (string)Dispatcher.Invoke(new Func<string>(() => (comboBoxAdapters.SelectedItem as NetworkAdapters).GUID)))); VentsTools.currentSettingString = "Не удалось поменять IP адрес"; } gatemark = NM.SetGateway(Vips.wincGate, (string)Dispatcher.Invoke(new Func<string>(() => (comboBoxAdapters.SelectedItem as NetworkAdapters).AdapterDescriptionFull))); // Thread.Sleep(3000); if (!gatemark) { _log.Error(String.Format("Не удалось изменить параметры сети Gateway={0}, adaperName={1}, adapterGuid={2}", Vips.wincGate, (string)Dispatcher.Invoke(new Func<string>(() => (comboBoxAdapters.SelectedItem as NetworkAdapters).AdapterDescriptionFull)), (string)Dispatcher.Invoke(new Func<string>(() => (comboBoxAdapters.SelectedItem as NetworkAdapters).GUID)))); VentsTools.currentSettingString = "Не удалось поменять шлюз"; } if (!ipmark && !gatemark) VentsTools.currentSettingString = "Не удалось изменить настройки сети"; else { bool compl = false; string message = "Текущий IP адрес - "; message += NM.GetIP(ref compl, (string)Dispatcher.Invoke(new Func<string>(() => (comboBoxAdapters.SelectedItem as NetworkAdapters).AdapterDescriptionFull)))[0]; message += "\r\nТекущая сеть: Wincos"; if (netbiosmark == false) message += "\r\nНе удалось поменять настройки Netbios"; VentsTools.currentSettingString = message; Dispatcher.Invoke(new Action(() => wincRect.Stroke = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFE8F5FC")))); Dispatcher.Invoke(new Action(() => wincRect.Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFE8F5FC")))); Dispatcher.Invoke(new Action(() => belsRect.Stroke = new SolidColorBrush(Colors.Transparent))); Dispatcher.Invoke(new Action(() => belsRect.Fill = new SolidColorBrush(Colors.Transparent))); //Запишем настройки в реестр //начнем а гуида сетевой RegistryWorker.WriteKeyValue(Microsoft.Win32.RegistryHive.LocalMachine, VentsConst._SETTINGSLOCATION, Microsoft.Win32.RegistryValueKind.String, VentsConst._LASTADPTGUID, (string)Dispatcher.Invoke(new Func<string>(() => (comboBoxAdapters.SelectedItem as NetworkAdapters).GUID))); //запишем настройки в стринг массиве для этого гуида string[] settArr = new string[] { Vips.belsIP, Vips.belsMask, Vips.belsGate, Vips.wincIP, Vips.wincMask, Vips.wincGate }; RegistryWorker.WriteKeyValue(Microsoft.Win32.RegistryHive.LocalMachine, VentsConst._ADAPTERSLOCATION, Microsoft.Win32.RegistryValueKind.MultiString, (string)Dispatcher.Invoke(new Func<string>(() => (comboBoxAdapters.SelectedItem as NetworkAdapters).GUID)), settArr); //запишем последнюю нажатую кнопку (выбранную сеть) RegistryWorker.WriteKeyValue(Microsoft.Win32.RegistryHive.LocalMachine, VentsConst._SETTINGSLOCATION, Microsoft.Win32.RegistryValueKind.String, VentsConst._LASTAPPLYBUTTONCLICKED, "WINCOS"); } } catch { _log.Error(String.Format("Недопустимое значение маски и IP адреса IP={0}, mask={1}, adaperName={2}, adapterGuid={3}", Vips.wincIP, Vips.wincMask, (string)Dispatcher.Invoke(new Func<string>(() => (comboBoxAdapters.SelectedItem as NetworkAdapters).AdapterDescriptionFull)), (string)Dispatcher.Invoke(new Func<string>(() => (comboBoxAdapters.SelectedItem as NetworkAdapters).AdapterDescriptionFull)))); VentsTools.currentSettingString = "Недопустимое значение маски и IP адреса!"; ProgressBarPerform = new KeyValuePair<bool, int>(false, 100); Dispatcher.Invoke(new Action(() => { applyBelsbutt.IsEnabled = true; applyWincbutt.IsEnabled = true; })); } } else { _log.Info("Нажата кнопка \"Применить настройки Белсолод\" без выбранного сетевого адаптера"); VentsTools.currentSettingString = "Сначала Выберите сетевой адаптер!"; } ProgressBarPerform = new KeyValuePair<bool, int>(false, 100); Dispatcher.Invoke(new Action(() => { applyBelsbutt.IsEnabled = true; applyWincbutt.IsEnabled = true; })); }
private void comboBoxAdapters_SelectedIndexChanged(object sender, SelectionChangedEventArgs e) { if (_cfgthread.ThreadState == ThreadState.Running || _cfgthread.ThreadState == ThreadState.Suspended) return; else { bool state = false; NetworkManagement NM = new NetworkManagement(); Vips = GetIPSettings((comboBoxAdapters.SelectedItem as NetworkAdapters).GUID); if (Vips.belsIP == null) Vips.belsIP = NM.GetIP(ref state, (string)Dispatcher.Invoke(new Func<string>(() => (comboBoxAdapters.SelectedItem as NetworkAdapters).AdapterDescriptionFull)))[0]; if (Vips.belsMask == null) Vips.belsMask = NM.GetSubnetMask(ref state, (string)Dispatcher.Invoke(new Func<string>(() => (comboBoxAdapters.SelectedItem as NetworkAdapters).AdapterDescriptionFull)))[0]; if (Vips.belsGate == null) Vips.belsGate = NM.GetGateway(ref state, (string)Dispatcher.Invoke(new Func<string>(() => (comboBoxAdapters.SelectedItem as NetworkAdapters).AdapterDescriptionFull)))[0]; if (Vips.wincIP == null) Vips.wincIP = VentsConst._DEFAULTWINCOSIP; if (Vips.wincMask == null) Vips.wincMask = VentsConst._DEFAULTWINCOSMASK; if (Vips.wincGate == null) Vips.wincGate = VentsConst._DEFAULTWINCOSGATEWAY; } }
static void Main(string[] args) { NetworkManagement.setDNS(args[0], args[1]); }
/// <summary> /// Constructor /// </summary> /// <param name="name">架構名稱</param> public CSModel(string name) : base(name) { NetworkManagement = new NetworkManagement(); }
private static void Main(string[] args) { ShowNicNames(); UserMessages.WelcomeMessage(); var isProcessing = false; while (!Console.KeyAvailable) { var keey = Console.ReadKey(true).Key; if (keey == ConsoleKey.Escape) { break; } if (choiceMade) { if (!string.IsNullOrEmpty(adaptorDescription)) { UserMessages.HelpKeysMessage(); if (keey == ConsoleKey.S && !isProcessing) { isProcessing = true; try { Console.WriteLine("S - Key pressed - Setting static IP then resetting to original"); Console.Write("Enter the Static IP:"); var staticIp = Console.ReadLine(); Console.Write("Subnet Mask (presss Enter to use 255.255.255.0):"); var subnetMask = Console.ReadLine(); if (string.IsNullOrEmpty(subnetMask)) { subnetMask = "255.255.255.0"; } var gatewayForAdaptor = NetworkManagement.GetGatewayForAdaptor(adaptorDescription); Console.Write("Gateway (presss Enter to use current {0}: ", gatewayForAdaptor); var gateway = Console.ReadLine(); if (string.IsNullOrEmpty(gateway)) { gateway = gatewayForAdaptor.ToString(); } isDhcp = !NetworkManagement.IsNetworkedWithStaticIp(adaptorDescription); if (isDhcp) { NetworkManagement.SetSystemIp(staticIp, subnetMask, adaptorDescription); NetworkManagement.SetSystemGateway(gateway, adaptorDescription); // Thread.Sleep(10000); // NetworkManagement.SetDhcp(adaptorDescription); // Thread.Sleep(10000); DisplayNics(true); } else { var currentIpAddress = NetworkUtils.GetIpFromAdaptorDesc(adaptorDescription); var currentGateway = gatewayForAdaptor; var currentsubnetMask = NetworkUtils.GetIp4MaskFromAdaptorDesc(adaptorDescription); NetworkManagement.SetSystemIp(staticIp, subnetMask, adaptorDescription); NetworkManagement.SetSystemGateway(gateway, adaptorDescription); //Thread.Sleep(10000); // NetworkManagement.SetSystemIp(currentIpAddress.ToString(), currentsubnetMask.ToString(), adaptorDescription); // NetworkManagement.SetSystemGateway(currentGateway.ToString(), adaptorDescription); DisplayNics(true); } isProcessing = false; } catch (Exception e) { Console.WriteLine(e); } } if (keey == ConsoleKey.D) { Console.WriteLine("D - Key pressed - setting to DHCP then resetting to original"); isProcessing = true; isDhcp = !NetworkManagement.IsNetworkedWithStaticIp(adaptorDescription); if (isDhcp) { Console.WriteLine("Already in DHCP - Skipping"); } else { var currentIpAddress = NetworkUtils.GetIpFromAdaptorDesc(adaptorDescription); var currentsubnetMask = NetworkUtils.GetIp4MaskFromAdaptorDesc(adaptorDescription); NetworkManagement.SetDhcp(adaptorDescription); Thread.Sleep(10000); NetworkManagement.SetSystemIp(currentIpAddress.ToString(), currentsubnetMask.ToString(), adaptorDescription); Thread.Sleep(10000); } isProcessing = false; DisplayNics(); } if (keey == ConsoleKey.E) { DisplayNics(true); } if (keey == ConsoleKey.I) { Console.WriteLine(NetworkUtils.ActiveNetworkInterface()); } if (keey == ConsoleKey.V) { NetworkUtils.ShowNetworkInterfaces(false, true); } if (keey == ConsoleKey.N) { ShowNicNames(); } if (keey == ConsoleKey.T) { Console.WriteLine("Key T Pressed - Is Static IP"); Console.WriteLine(NetworkUtils.GetAdapterIp4Address(adaptorDescription)); Console.WriteLine(NetworkManagement.IsNetworkedWithStaticIp(adaptorDescription)); } if (keey == ConsoleKey.G) { try { Console.Write("Key G Pressed - Enter the gateway IP:"); var gateway = Console.ReadLine(); Console.WriteLine(" Set the Gateway to {0} ", gateway); Console.WriteLine(NetworkManagement.SetSystemGateway(gateway, adaptorDescription)); } catch (Exception e) { Console.WriteLine(e); } } if (keey == ConsoleKey.F) { var Ip = NetworkUtils.GetRandomIp(); Console.WriteLine("Key F Pressed - Set the IP to : " + Ip); NetworkManagement.SetSystemIp(Ip, "255.255.255.0", adaptorDescription); Thread.Sleep(5000); NetworkUtils.ShowNetworkInterfaces(true, false); } if (keey == ConsoleKey.M) { Console.WriteLine("Returning to Nic Adaptor Selection"); choiceMade = false; DisplayNics(); } } else { Console.WriteLine("Adapter is not set"); choiceMade = false; } } else { switch (keey) { case ConsoleKey.NumPad1: case ConsoleKey.D1: SetActiveNetworkAdaptor(1); break; case ConsoleKey.NumPad2: case ConsoleKey.D2: SetActiveNetworkAdaptor(2); break; case ConsoleKey.NumPad3: case ConsoleKey.D3: SetActiveNetworkAdaptor(3); break; case ConsoleKey.NumPad4: case ConsoleKey.D4: SetActiveNetworkAdaptor(4); break; case ConsoleKey.NumPad5: case ConsoleKey.D5: SetActiveNetworkAdaptor(5); break; case ConsoleKey.NumPad6: case ConsoleKey.D6: SetActiveNetworkAdaptor(6); break; case ConsoleKey.NumPad7: case ConsoleKey.D7: SetActiveNetworkAdaptor(7); break; default: Console.WriteLine("Invalid Selection"); break; } } } }