/// <summary> /// Remove All IPConfig /// </summary> public static void RemoveAllConfigIP() { AddressMap.Clear(); MACMap.Clear(); IPConfig.RemoveAll(); NetworkConfiguration.ClearConfigs(); }
/// <summary> /// CommandIPConfig /// </summary> /// <param name="arguments">Arguments</param> public override ReturnInfo Execute(List <string> arguments) { if (arguments[0] == "/release") { var xClient = new DHCPClient(); xClient.SendReleasePacket(); xClient.Close(); NetworkConfiguration.ClearConfigs(); } else if (arguments[0] == "/ask") { var xClient = new DHCPClient(); if (xClient.SendDiscoverPacket() != -1) { xClient.Close(); Kernel.console.WriteLine("Configuration applied! Your local IPv4 Address is " + NetworkConfiguration.CurrentAddress + "."); } else { NetworkConfiguration.ClearConfigs(); xClient.Close(); return(new ReturnInfo(this, ReturnCode.ERROR, "DHCP Discover failed. Can't apply dynamic IPv4 address.")); } } else if (arguments[0] == "/listnic") { foreach (var device in NetworkDevice.Devices) { switch (device.CardType) { case CardType.Ethernet: Kernel.console.WriteLine("Ethernet Card - " + device.NameID + " - " + device.Name + " (" + device.MACAddress + ")"); break; case CardType.Wireless: Kernel.console.WriteLine("Wireless Card - " + device.NameID + " - " + device.Name + " (" + device.MACAddress + ")"); break; } } } else if (arguments[0] == "/set") { if ((arguments.Count == 3) || (arguments.Count == 4)) // ipconfig /set eth0 192.168.1.2/24 {gw} { string[] adrnetwork = arguments[2].Split('/'); Address ip = Address.Parse(adrnetwork[0]); NetworkDevice nic = NetworkDevice.GetDeviceByName(arguments[1]); Address gw = null; if (arguments.Count == 4) { gw = Address.Parse(arguments[3]); } int cidr; try { cidr = int.Parse(adrnetwork[1]); } catch (Exception ex) { return(new ReturnInfo(this, ReturnCode.ERROR, ex.Message)); } Address subnet = Address.CIDRToAddress(cidr); if (nic == null) { return(new ReturnInfo(this, ReturnCode.ERROR, "Couldn't find network device: " + arguments[1])); } if (ip != null && subnet != null && gw != null) { IPConfig.Enable(nic, ip, subnet, gw); Kernel.console.WriteLine("Config OK!"); } else if (ip != null && subnet != null) { IPConfig.Enable(nic, ip, subnet, ip); Kernel.console.WriteLine("Config OK!"); } else { return(new ReturnInfo(this, ReturnCode.ERROR, "Can't parse IP addresses (make sure they are well formated).")); } } else { return(new ReturnInfo(this, ReturnCode.ERROR, "Usage : ipconfig /set {device} {IPv4/CIDR} {Gateway|null}")); } } else if (arguments[0] == "/nameserver") { if (arguments[1] == "-add") { DNSConfig.Add(Address.Parse(arguments[2])); Kernel.console.WriteLine(arguments[2] + " has been added to nameservers."); } else if (arguments[1] == "-rem") { DNSConfig.Remove(Address.Parse(arguments[2])); Kernel.console.WriteLine(arguments[2] + " has been removed from nameservers list."); } else { return(new ReturnInfo(this, ReturnCode.ERROR, "Usage : ipconfig /nameserver {add|remove} {IP}")); } } else { return(new ReturnInfo(this, ReturnCode.ERROR, "Wrong usage, please type: ipconfig /help")); } return(new ReturnInfo(this, ReturnCode.OK)); }