Beispiel #1
0
        public static void c_IPConfig(string cmd)
        {
            string[] args = cmd.Split(' ');

            if (args.Length == 1)
            {
                Console.WriteLine("IP Config");
                return;
            }

            if (args[1] == "/release")
            {
                Network.DHCP.Core.SendReleasePacket();
            }
            else if (args[1] == "/interfaces")
            {
                Utilities.Settings settings = new Utilities.Settings(@"0:\netinterface.conf");
                int i = 0;
                foreach (String s in NetworkInterfaces.CustomName)
                {
                    Console.WriteLine(s + " " + settings.Get(s) + " " + NetworkInterfaces.PCIName[i]);
                    i++;
                }
            }
            else if (args[1] == "/interface")
            {
                Console.WriteLine(NetworkInterfaces.Interface(args[2]));
            }
            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")
                    {
                        Utilities.Settings settings = new Utilities.Settings(@"0:\" + 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")
            {
                Network.DHCP.Core.SendDiscoverPacket();
            }
            else
            {
                Console.WriteLine("IP Config");
            }
        }
Beispiel #2
0
        /// <summary>
        /// c = command, c_Ping
        /// </summary>
        /// <param name="arg">IP Address</param>
        /// /// <param name="startIndex">The start index for remove.</param>
        /// <param name="count">The count index for remove.</param>
        public static void c_Ping(string arg, short startIndex = 0, short count = 5)
        {
            if (Misc.IsIpv4Address(arg))
            {
                string[] items = arg.Split('.');

                int PacketSent     = 0;
                int PacketReceived = 0;
                int PacketLost     = 0;

                int PercentLoss = 0;

                try
                {
                    Address destination = new Address((byte)int.Parse(items[0]), (byte)int.Parse(items[1]), (byte)int.Parse(items[2]), (byte)int.Parse(items[3]));
                    Address source      = Config.FindNetwork(destination);

                    int _deltaT = 0;
                    int second;

                    for (int i = 0; i < 4; i++)
                    {
                        second = 0;
                        Console.WriteLine("Sending ping to " + destination.ToString() + "...");

                        System.Utilities.WaitSeconds(1);

                        try
                        {
                            ICMPEchoRequest request = new ICMPEchoRequest(source, destination, 0x0001, 0x50); //this is working
                            OutgoingBuffer.AddPacket(request);                                                //Aura doesn't work when this is called.
                            NetworkStack.Update();
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Error on ping " + i + ": " + ex);
                        }

                        PacketSent++;

                        while (true)
                        {
                            if (ICMPPacket.recvd_reply != null)
                            {
                                //if (ICMPPacket.recvd_reply.SourceIP == destination)
                                //{

                                if (second < 1)
                                {
                                    Console.WriteLine("Reply received from " + ICMPPacket.recvd_reply.SourceIP.ToString() + " time < 1s");
                                }
                                else if (second >= 1)
                                {
                                    Console.WriteLine("Reply received from " + ICMPPacket.recvd_reply.SourceIP.ToString() + " time " + second + "s");
                                }

                                PacketReceived++;

                                ICMPPacket.recvd_reply = null;
                                break;
                                //}
                            }

                            if (second >= 5)
                            {
                                Console.WriteLine("Destination host unreachable.");
                                PacketLost++;
                                break;
                            }

                            if (_deltaT != Cosmos.HAL.RTC.Second)
                            {
                                second++;
                                _deltaT = Cosmos.HAL.RTC.Second;
                            }
                        }
                    }
                }
                catch
                {
                    Console.WriteLine("Internal error.");
                }
                finally
                {
                    PercentLoss = 25 * PacketLost;

                    Console.WriteLine();
                    Console.WriteLine("Ping statistics for " + arg + ":");
                    Console.WriteLine("    Packets: Sent = " + PacketSent + ", Received = " + PacketReceived + ", Lost = " + PacketLost + " (" + PercentLoss + "% loss)");
                }
            }
            else
            {
                Network.IPV4.UDP.DNS.DNSClient DNSRequest = new Network.IPV4.UDP.DNS.DNSClient(53);
                DNSRequest.Ask(arg);
                int _deltaT = 0;
                int second  = 0;
                while (!DNSRequest.ReceivedResponse)
                {
                    if (_deltaT != Cosmos.HAL.RTC.Second)
                    {
                        second++;
                        _deltaT = Cosmos.HAL.RTC.Second;
                    }

                    if (second >= 4)
                    {
                        //Apps.System.Debugger.debugger.Send("No response in 4 secondes...");
                        break;
                    }
                }
                DNSRequest.Close();
                c_Ping("     " + DNSRequest.address.ToString());
            }
        }