示例#1
0
 public string checkConnectivity(IPv4 newIP)
 {
     if (Number1 == newIP.Number1 && Number2 == newIP.Number2 && Number3 == newIP.Number3 && NetMask == newIP.NetMask)
     {
         return("The IPs are in the same Network.");
     }
     else
     {
         return("The IPs are not in the same Network.");
     }
 }
示例#2
0
        static void showConnectivity()
        /* Asks for a new IP and then compares it with the Ip that the user inserted before.*/
        {
            Console.Clear();
            Console.WriteLine("Please insert the new IPv4 Adress: ");
            Console.Write("First Octet: ");
            int num1 = int.Parse(Console.ReadLine());

            Console.Write("Second Octet: ");
            int num2 = int.Parse(Console.ReadLine());

            Console.Write("Third Octet: ");
            int num3 = int.Parse(Console.ReadLine());

            Console.Write("Forth Octet: ");
            int num4 = int.Parse(Console.ReadLine());

            Console.Write("Network Mask: ");
            int netMask = int.Parse(Console.ReadLine());

            IPv4 newIp = new IPv4(num1, num2, num3, num4, netMask);

            if (newIp.validateIPv4() == true)
            {
                Console.WriteLine($"\nYour IPv4 is valid and you can see if here: {newIp.printToConsole()}");
                Console.WriteLine("\nPress any key to continue.");
                Console.ReadKey();
            }
            else
            {
                Console.WriteLine("\nInvalid IPv4.");
                Console.WriteLine("\nPress any key to repeat.");
                Console.ReadKey();
            }

            Console.Clear();
            foreach (IPv4 userIp in listIpInUse)
            {
                Console.WriteLine(userIp.printToConsole());
                string matches = userIp.checkConnectivity(newIp);
                Console.WriteLine($"The Connectivity test resulted in: {matches}");
                Console.WriteLine("\nPress any key to continue.");
                Console.ReadKey();
            }
        }
示例#3
0
        static void newIPv4()
        {
            listIpInUse.Clear();
            int flag = 0;

            do
            {
                Console.Clear();
                Console.WriteLine("Please insert the IPv4 Adress: ");
                Console.Write("First Octet: ");
                int num1 = int.Parse(Console.ReadLine());
                Console.Write("Second Octet: ");
                int num2 = int.Parse(Console.ReadLine());
                Console.Write("Third Octet: ");
                int num3 = int.Parse(Console.ReadLine());
                Console.Write("Forth Octet: ");
                int num4 = int.Parse(Console.ReadLine());
                Console.Write("Network Mask: ");
                int netMask = int.Parse(Console.ReadLine());

                IPv4 i = new IPv4(num1, num2, num3, num4, netMask);

                if (i.validateIPv4() == true)
                {
                    flag = 1;
                    listIpInUse.Add(new IPv4(i));
                    Console.WriteLine($"\nYour IPv4 is valid and you can see if here: {i.printToConsole()}");
                }
                else
                {
                    Console.WriteLine("\nInvalid IPv4.");
                    Console.WriteLine("\nPress any key to repeat.");
                    Console.ReadKey();
                }
            } while (flag == 0);

            Console.WriteLine("\nPress any key to continue.");
            Console.ReadKey();
            auxiliaryMenu();
        }
示例#4
0
 public IPv4(IPv4 i)
 {
     Number1 = i._numbs[0]; Number2 = i._numbs[1]; Number3 = i._numbs[2]; Number4 = i._numbs[3];
     NetMask = i._netMask;
 }
示例#5
0
        static void pickIPv4FromFavourites()

        /* This method reads the .txt file where the favourite IPs are and pastes it to a list. Then checks the list to see if it is empty, in case the .txt file was empty. If it is empty, it skips and informs the user the list
         * is empty, going back to the main menu. If there are ips inside, it shows the ips, asks which one the user wants to use (checking if the chosen ip exists, if it does not exist, it asks the user to choose again), and if it
         * does exist, it pastes it into another list (IpInUse) to be used later in the program. It ends by going into the auxiliary menu. */
        {
            Console.Clear();

            StreamReader rd = new StreamReader(@"FAVOURITEIPV4.txt");

            while (!rd.EndOfStream)
            {
                string   line = rd.ReadLine();
                string[] iPv4 = line.Split('.');
                IPv4     i    = new IPv4(int.Parse(iPv4[0]), int.Parse(iPv4[1]), int.Parse(iPv4[2]), int.Parse(iPv4[3]), int.Parse(iPv4[4]));
                listFavouriteIPv4.Add(new IPv4(i));
            }
            rd.Close();

            if (listFavouriteIPv4.Count != 0)
            {
                int counter = 0;
                Console.WriteLine("This is the list of saved favourite IPv4:");
                Console.WriteLine();
                foreach (IPv4 IPs in listFavouriteIPv4)
                {
                    Console.WriteLine(++counter + ")\n" + IPs.ToString());
                }

                int flag = 0;
                do
                {
                    Console.WriteLine("Which IPv4 would you like to choose?");
                    int favIP = int.Parse(Console.ReadLine());

                    if (favIP <= 0 && favIP > listIpInUse.Count())
                    {
                        Console.Clear();
                        Console.WriteLine("That IPv4 does not exist.");
                        Console.WriteLine("Press any key to continue.");
                        Console.ReadKey();
                    }
                    else
                    {
                        Console.Clear();
                        IPv4 f = new IPv4(listFavouriteIPv4[favIP - 1]);
                        listIpInUse.Add(new IPv4(f));
                        Console.WriteLine($"\nThe following IP was selected:\n{f.printToConsole()}");
                        flag = 1;
                        Console.WriteLine("Press any key to continue.");
                        Console.ReadKey();
                        auxiliaryMenu();
                    }
                }while (flag == 0);
            }
            else
            {
                Console.WriteLine("The favourites list is empty.\n");
                Console.WriteLine("Press any key to continue.");
                Console.ReadKey();
            }
        }