/* * Method called to applied the differents options received in the DHCP packet ACK **/ /// <summary> /// Apply the new IP configuration received. /// </summary> /// <param name="Options">DHCPOption class using the packetData from the received dhcp packet.</param> /// <param name="message">Enable/Disable the displaying of messages about DHCP applying and conf. Disabled by default. /// </param> public static void Apply(DHCPOption Options, bool message = false) { NetworkStack.RemoveAllConfigIP(); //cf. Roadmap. (have to change this, because some network interfaces are not configured in dhcp mode) [have to be done in 0.5.x] foreach (NetworkDevice networkDevice in NetworkDevice.Devices) { if (message) { Console.WriteLine(); Console.WriteLine("[DHCP ACK][" + networkDevice.Name + "] Packet received, applying IP configuration..."); Console.WriteLine(" IP Address : " + Options.Address().ToString()); Console.WriteLine(" Subnet mask : " + Options.Subnet().ToString()); Console.WriteLine(" Gateway : " + Options.Gateway().ToString()); Console.WriteLine(" DNS server : " + Options.DNS01().ToString()); } Settings settings = new Settings(@"0:\" + networkDevice.Name + ".conf"); settings.EditValue("ipaddress", Options.Address().ToString()); settings.EditValue("subnet", Options.Subnet().ToString()); settings.EditValue("gateway", Options.Gateway().ToString()); settings.EditValue("dns01", Options.DNS01().ToString()); settings.EditValue("dhcp_server", Options.Server().ToString()); settings.PushValues(); NetworkInit.Enable(); if (message) { Console.WriteLine("[DHCP CONFIG][" + networkDevice.Name + "] IP configuration applied."); Console.WriteLine(); DHCPAsked = false; } } }
/// <summary> /// Start Aura after login. /// </summary> private static void Start(string username) { Console.Clear(); Kernel.SystemExists = true; Kernel.userLogged = username; Kernel.JustInstalled = true; Kernel.running = true; Console.Clear(); Utils.Settings config = new Utils.Settings(@"0:\System\settings.conf"); string debugger = config.GetValue("debugger"); if (debugger == "on") { Kernel.debugger.enabled = true; } NetworkInit.Enable(); WelcomeMessage.Display(); Text.Display("logged", username); Console.WriteLine(); Kernel.Logged = true; }
/// <summary> /// Send a packet to find the DHCP server and tell that we want a new IP address /// </summary> public static void SendDiscoverPacket() { NetworkStack.RemoveAllConfigIP(); foreach (NetworkDevice networkDevice in NetworkDevice.Devices) { NetworkInit.Enable(networkDevice, new Network.IPV4.Address(0, 0, 0, 0), new Network.IPV4.Address(0, 0, 0, 0), new Network.IPV4.Address(0, 0, 0, 0)); DHCPDiscover dhcp_discover = new DHCPDiscover(networkDevice.MACAddress); OutgoingBuffer.AddPacket(dhcp_discover); NetworkStack.Update(); DHCPAsked = true; } }
/* * Method called to applied the differents options received in the DHCP packet ACK **/ /// <summary> /// Apply the new IP configuration received. /// </summary> /// <param name="Options">DHCPOption class using the packetData from the received dhcp packet.</param> /// <param name="message">Enable/Disable the displaying of messages about DHCP applying and conf. Disabled by default. /// </param> public static void Apply(DHCPAck packet, bool message = false) { NetworkStack.RemoveAllConfigIP(); //cf. Roadmap. (have to change this, because some network interfaces are not configured in dhcp mode) [have to be done in 0.5.x] foreach (NetworkDevice networkDevice in NetworkDevice.Devices) { if (packet.Client.ToString() == null || packet.Client.ToString() == null || packet.Client.ToString() == null || packet.Client.ToString() == null) { CustomConsole.WriteLineError("Parsing DHCP ACK Packet failed, can't apply network configuration."); } else { if (message) { Console.WriteLine(); CustomConsole.WriteLineInfo("[DHCP ACK][" + networkDevice.Name + "] Packet received, applying IP configuration..."); CustomConsole.WriteLineInfo(" IP Address : " + packet.Client.ToString()); CustomConsole.WriteLineInfo(" Subnet mask : " + packet.Subnet.ToString()); CustomConsole.WriteLineInfo(" Gateway : " + packet.Server.ToString()); CustomConsole.WriteLineInfo(" DNS server : " + packet.DNS.ToString()); } Utils.Settings settings = new Utils.Settings(@"0:\System\" + networkDevice.Name + ".conf"); settings.EditValue("ipaddress", packet.Client.ToString()); settings.EditValue("subnet", packet.Subnet.ToString()); settings.EditValue("gateway", packet.Server.ToString()); settings.EditValue("dns01", packet.DNS.ToString()); settings.EditValue("dhcp_server", packet.Server.ToString()); settings.PushValues(); NetworkInit.Enable(networkDevice, packet.Client, packet.Subnet, packet.Server, packet.DNS); if (message) { CustomConsole.WriteLineOK("[DHCP CONFIG][" + networkDevice.Name + "] IP configuration applied."); Console.WriteLine(); DHCPAsked = false; } } } Kernel.BeforeCommand(); }
/// <summary> /// c = command, c_SystemInfomation /// </summary> public static void c_IPConfig(string cmd) { string[] args = cmd.Split(' '); if (args.Length == 1) { L.List_Translation.Ipconfig(); return; } if (args[1] == "/release") { System.Network.DHCP.Core.SendReleasePacket(); } else if (args[1] == "/set") { if (args.Length <= 3) { Console.WriteLine("Usage : " + args[0] + " /set {interface} {IPv4} {Subnet} -g {Gateway} -d {PrimaryDNS}"); //ipconfig /set PCNETII 192.168.1.32 255.255.255.0 -g 192.168.1.254 -d 8.8.8.8 } else { if (NetworkInterfaces.Interface(args[2]) != "null") { Utils.Settings settings = new Utils.Settings(@"0:\System\" + NetworkInterfaces.Interface(args[2]) + ".conf"); NetworkStack.RemoveAllConfigIP(); ApplyIP(args, settings); settings.Push(); NetworkInit.Enable(); } else { Console.WriteLine("This interface doesn't exists."); } } } else if (args[1] == "/renew") { System.Network.DHCP.Core.SendDiscoverPacket(); } else { L.List_Translation.Ipconfig(); } }
/// <summary> /// Send a packet to the DHCP server to make the address available again /// </summary> public static void SendReleasePacket() { foreach (NetworkDevice networkDevice in NetworkDevice.Devices) { Address source = Config.FindNetwork(DHCPServerAddress(networkDevice)); DHCPRelease dhcp_release = new DHCPRelease(source, DHCPServerAddress(networkDevice)); OutgoingBuffer.AddPacket(dhcp_release); NetworkStack.Update(); NetworkStack.RemoveAllConfigIP(); Settings settings = new Settings(@"0:\" + networkDevice.Name + ".conf"); settings.EditValue("ipaddress", "0.0.0.0"); settings.EditValue("subnet", "0.0.0.0"); settings.EditValue("gateway", "0.0.0.0"); settings.EditValue("dns01", "0.0.0.0"); settings.PushValues(); NetworkInit.Enable(); } }
/// <summary> /// CommandIPConfig /// </summary> /// <param name="arguments">Arguments</param> public override ReturnInfo Execute(List <string> arguments) { if (arguments[0] == "/release") { DHCPClient.SendReleasePacket(); } else if (arguments[0] == "/ask") { DHCPClient.SendDiscoverPacket(); } else if (arguments[0] == "/listnic") { foreach (var device in NetworkDevice.Devices) { switch (device.CardType) { case CardType.Ethernet: Console.WriteLine("Ethernet Card - " + device.NameID + " - " + device.Name + " (" + device.MACAddress + ")"); break; case CardType.Wireless: Console.WriteLine("Wireless Card - " + device.NameID + " - " + device.Name + " (" + device.MACAddress + ")"); break; } } } else if (arguments[0] == "/set") { if (arguments.Count < 5) { return(new ReturnInfo(this, ReturnCode.ERROR, "Usage : ipconfig /set {device} {IPv4} {Subnet} {Gateway}")); } else { Address ip = Address.Parse(arguments[2]); Address subnet = Address.Parse(arguments[3]); Address gw = Address.Parse(arguments[4]); NetworkDevice nic = NetworkDevice.GetDeviceByName(arguments[1]); if (nic == null) { return(new ReturnInfo(this, ReturnCode.ERROR, "Couldn't find network device: " + arguments[1])); } if (ip != null && subnet != null && gw != null) { NetworkInit.Enable(nic, ip, subnet, gw, gw); Console.WriteLine("Config OK!"); } else { return(new ReturnInfo(this, ReturnCode.ERROR, "Can't parse IP addresses (make sure they are well formated).")); } /*if (NetworkInterfaces.Interface(arguments[1]) != "null") * { * Utils.Settings settings = new Utils.Settings(@"0:\System\" + NetworkInterfaces.Interface(arguments[1]) + ".conf"); * NetworkStack.RemoveAllConfigIP(); * ApplyIP(arguments.ToArray(), settings); //TODO Fix that (arguments) * settings.Push(); * } * else * { * Console.WriteLine("This interface doesn't exists."); * } */ } } else { return(new ReturnInfo(this, ReturnCode.ERROR, "Wrong usage, please type: ipconfig /help")); } return(new ReturnInfo(this, ReturnCode.OK)); }