Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Console.OutputEncoding = System.Text.Encoding.UTF8;
- int subnetCount = 0;
- string networkClass = string.Empty;
- string networkClassLowerCase = string.Empty;
- string ipDec = string.Empty;
- string ipBin = string.Empty;
- string smDec = string.Empty;
- string smBin = string.Empty;
- string naDec = string.Empty;
- string naBin = string.Empty;
- string brADec = string.Empty;
- string brABin = string.Empty;
- string rangeFrom = string.Empty;
- string rangeTo = string.Empty;
- string smSubnetDec = string.Empty;
- string smSubnetBin = string.Empty;
- string naBin1 = string.Empty;
- string naDec1 = string.Empty;
- string brABin1 = string.Empty;
- string brADec1 = string.Empty;
- string rangeFrom1 = string.Empty;
- string rangeTo1 = string.Empty;
- string naBin2 = string.Empty;
- string naDec2 = string.Empty;
- string brABin2 = string.Empty;
- string brADec2 = string.Empty;
- string rangeFrom2 = string.Empty;
- string rangeTo2 = string.Empty;
- string naBin3 = string.Empty;
- string naDec3 = string.Empty;
- string brABin3 = string.Empty;
- string brADec3 = string.Empty;
- string rangeFrom3 = string.Empty;
- string rangeTo3 = string.Empty;
- string naBinRandom = string.Empty;
- string naDecRandom = string.Empty;
- string brABinRandom = string.Empty;
- string brADecRandom = string.Empty;
- string rangeFromRandom = string.Empty;
- string rangeToRandom = string.Empty;
- Console.ForegroundColor = ConsoleColor.White;
- string input = Console.ReadLine();
- input = input.Replace(".", " ");
- List<string> inputs = input.Split(" ").ToList();
- string binary1 = Convert.ToString(int.Parse(inputs[0]), 2);
- string binary2 = Convert.ToString(int.Parse(inputs[1]), 2);
- string binary3 = Convert.ToString(int.Parse(inputs[2]), 2);
- string binary4 = Convert.ToString(int.Parse(inputs[3]), 2);
- string ip1 = string.Empty;
- string ip2 = string.Empty;
- string ip3 = string.Empty;
- string ip4 = string.Empty;
- ip1 = IP(binary1, ip1);
- ip2 = IP(binary2, ip2);
- ip3 = IP(binary3, ip3);
- ip4 = IP(binary4, ip4);
- ipBin = $"{ip1}.{ip2}.{ip3}.{ip4}";
- ipDec = $"{inputs[0]}.{inputs[1]}.{inputs[2]}.{inputs[3]}";
- List<string> iPDec = ipDec.Split(".").ToList();
- if (ip1.StartsWith("110"))
- {
- networkClass = "C";
- networkClassLowerCase = "c";
- smBin = "11111111.11111111.11111111.00000000";
- smDec = "255.255.255.0";
- naBin = $"{ip1}.{ip2}.{ip3}.00000000";
- naDec = $"{inputs[0]}.{inputs[1]}.{inputs[2]}.0";
- brABin = $"{ip1}.{ip2}.{ip3}.11111111";
- brADec = $"{inputs[0]}.{inputs[1]}.{inputs[2]}.255";
- rangeFrom = $"{inputs[0]}.{inputs[1]}.{inputs[2]}.1 ";
- rangeTo = $"{inputs[0]}.{inputs[1]}.{inputs[2]}.254";
- }
- else if (ip1.StartsWith("0"))
- {
- networkClass = "A";
- networkClassLowerCase = "a";
- smBin = $"11111111.00000000.00000000.00000000";
- smDec = $"255.0.0.0";
- naBin = $"{ip1}.00000000.00000000.00000000";
- naDec = $"{inputs[0]}.0.0.0";
- brABin = $"{ip1}.11111111.11111111.11111111";
- brADec = $"{inputs[0]}.255.255.255";
- rangeFrom = $"{inputs[0]}.0.0.1";
- rangeTo = $"{inputs[0]}.255.255.254";
- }
- else if (ip1.StartsWith("1"))
- {
- networkClass = "B";
- networkClassLowerCase = "b";
- smBin = $"11111111.11111111.00000000.00000000";
- smDec = $"255.255.0.0";
- naBin = $"{ip1}.{ip2}.00000000.00000000";
- naDec = $"{inputs[0]}.{inputs[1]}.0.0";
- brABin = $"{ip1}.{ip2}.11111111.11111111";
- brADec = $"{inputs[0]}.{inputs[1]}.255.255";
- rangeFrom = $"{inputs[0]}.{inputs[1]}.0.1";
- rangeTo = $"{inputs[0]}.{inputs[1]}.255.254";
- }
- int power = 0;
- subnetCount = int.Parse(inputs[4]);
- while (true)
- {
- if (int.Parse(iPDec[0]) > 255 || int.Parse(iPDec[1]) > 255 || int.Parse(iPDec[2]) > 255 || int.Parse(iPDec[3]) > 255)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("IP с число над 255, не може да съществува!");
- Console.ForegroundColor = ConsoleColor.White;
- input = Console.ReadLine();
- input = input.Replace(".", " ");
- iPDec = input.Split(" ").ToList();
- }
- else if (ip1.StartsWith("110") && subnetCount > 255)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("Не може да се създадат повече от 255 подмрежи с Class C мрежа!");
- Console.ForegroundColor = ConsoleColor.White;
- input = Console.ReadLine();
- input = input.Replace(".", " ");
- iPDec = input.Split(" ").ToList();
- }
- else if (ip1.StartsWith("0") && subnetCount > 16777215)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("Не може да се създадат повече от 16 777 215 подмрежи с Class А мрежа!");
- Console.ForegroundColor = ConsoleColor.White;
- input = Console.ReadLine();
- input = input.Replace(".", " ");
- iPDec = input.Split(" ").ToList();
- }
- else if (ip1.StartsWith("1") && subnetCount > 65535)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("Не може да се създадат повече от 65 535 подмрежи с Class B мрежа!");
- Console.ForegroundColor = ConsoleColor.White;
- input = Console.ReadLine();
- input = input.Replace(".", " ");
- iPDec = input.Split(" ").ToList();
- }
- else
- {
- for (int n = 0; n < 25; n++)
- {
- if (subnetCount <= Math.Pow(2, n))
- {
- power = n;
- break;
- }
- }
- if (ip1.StartsWith("110"))
- {
- smSubnetBin = "11111111.11111111.11111111";
- for (int q = 0; q < power; q++)
- {
- smSubnetBin += "1";
- }
- while (smSubnetBin.Length < 34)
- {
- smSubnetBin += "0";
- }
- smSubnetBin = smSubnetBin.Insert(26, ".");
- List<string> sMS = smSubnetBin.Split(".").ToList();
- smSubnetDec = $"{Convert.ToInt32(sMS[0], 2)}.{Convert.ToInt32(sMS[1], 2)}.{Convert.ToInt32(sMS[2], 2)}.{Convert.ToInt32(sMS[3], 2)}";
- }
- else if (ip1.StartsWith("0"))
- {
- smSubnetBin = "11111111";
- for (int q = 0; q < power; q++)
- {
- smSubnetBin += "1";
- }
- while (smSubnetBin.Length < 32)
- {
- smSubnetBin += "0";
- }
- smSubnetBin = smSubnetBin.Insert(8, ".");
- smSubnetBin = smSubnetBin.Insert(17, ".");
- smSubnetBin = smSubnetBin.Insert(26, ".");
- List<string> sMS = smSubnetBin.Split(".").ToList();
- smSubnetDec = $"{Convert.ToInt32(sMS[0], 2)}.{Convert.ToInt32(sMS[1], 2)}.{Convert.ToInt32(sMS[2], 2)}.{Convert.ToInt32(sMS[3], 2)}";
- }
- else if (ip1.StartsWith("1"))
- {
- smSubnetBin = "11111111.11111111";
- for (int q = 0; q < power; q++)
- {
- smSubnetBin += "1";
- }
- while (smSubnetBin.Length < 33)
- {
- smSubnetBin += "0";
- }
- smSubnetBin = smSubnetBin.Insert(17, ".");
- smSubnetBin = smSubnetBin.Insert(26, ".");
- List<string> sMS = smSubnetBin.Split(".").ToList();
- smSubnetDec = $"{Convert.ToInt32(sMS[0], 2)}.{Convert.ToInt32(sMS[1], 2)}.{Convert.ToInt32(sMS[2], 2)}.{Convert.ToInt32(sMS[3], 2)}";
- }
- break;
- }
- binary1 = Convert.ToString(int.Parse(iPDec[0]), 2);
- binary2 = Convert.ToString(int.Parse(iPDec[1]), 2);
- binary3 = Convert.ToString(int.Parse(iPDec[2]), 2);
- binary4 = Convert.ToString(int.Parse(iPDec[3]), 2);
- ip1 = string.Empty;
- ip2 = string.Empty;
- ip3 = string.Empty;
- ip4 = string.Empty;
- ip1 = IP(binary1, ip1);
- ip2 = IP(binary2, ip2);
- ip3 = IP(binary3, ip3);
- ip4 = IP(binary4, ip4);
- ipBin = $"{ip1}.{ip2}.{ip3}.{ip4}";
- subnetCount = int.Parse(iPDec[4]);
- }
- if (ip1.StartsWith("110"))
- {
- naBin = ip1 + "." + ip2 + "." + ip3;
- brABin = ip1 + "." + ip2 + "." + ip3;
- List<string> subnet1 = SubnetMath(1, naBin ,power, brABin, rangeFrom, rangeTo);
- }
- /*else if (ip1.StartsWith("0"))
- {
- if (inputs[0] == "Subnet")
- {
- string binarySubnetNumber = Convert.ToString(int.Parse(inputs[1]), 2);
- string NetworkAdressSubnet = ip1;
- for (int a = binarySubnetNumber.Length; a < power; a++)
- {
- NetworkAdressSubnet += "0";
- }
- NetworkAdressSubnet += binarySubnetNumber;
- while (NetworkAdressSubnet.Length < 32)
- {
- NetworkAdressSubnet += "0";
- }
- NetworkAdressSubnet = NetworkAdressSubnet.Insert(8, ".");
- NetworkAdressSubnet = NetworkAdressSubnet.Insert(17, ".");
- NetworkAdressSubnet = NetworkAdressSubnet.Insert(26, ".");
- List<string> nAS = NetworkAdressSubnet.Split(".").ToList();
- string BroadcastAdressSubnet = ip1;
- for (int a = binarySubnetNumber.Length; a < power; a++)
- {
- BroadcastAdressSubnet += "0";
- }
- BroadcastAdressSubnet += binarySubnetNumber;
- while (BroadcastAdressSubnet.Length < 32)
- {
- BroadcastAdressSubnet += "1";
- }
- BroadcastAdressSubnet = BroadcastAdressSubnet.Insert(8, ".");
- BroadcastAdressSubnet = BroadcastAdressSubnet.Insert(17, ".");
- BroadcastAdressSubnet = BroadcastAdressSubnet.Insert(26, ".");
- List<string> bNS = BroadcastAdressSubnet.Split(".").ToList();
- Console.WriteLine();
- Console.WriteLine("Network Adress: " + NetworkAdressSubnet);
- Console.WriteLine($"Network Adress: {Convert.ToInt32(nAS[0], 2)}.{Convert.ToInt32(nAS[1], 2)}.{Convert.ToInt32(nAS[2], 2)}.{Convert.ToInt32(nAS[3], 2)}");
- Console.WriteLine();
- Console.WriteLine("Broadcast Adress: " + BroadcastAdressSubnet);
- Console.WriteLine($"Broadcast Adress: {Convert.ToInt32(bNS[0], 2)}.{Convert.ToInt32(bNS[1], 2)}.{Convert.ToInt32(bNS[2], 2)}.{Convert.ToInt32(bNS[3], 2)}");
- Console.WriteLine();
- Console.WriteLine($"Range: {Convert.ToInt32(nAS[0], 2)}.{Convert.ToInt32(nAS[1], 2)}.{Convert.ToInt32(nAS[2], 2)}.{Convert.ToInt32(nAS[3], 2) + 1} to {Convert.ToInt32(bNS[0], 2)}.{Convert.ToInt32(bNS[1], 2)}.{Convert.ToInt32(bNS[2], 2)}.{Convert.ToInt32(bNS[3], 2) - 1}");
- Console.WriteLine("========================================================================================================================");
- }
- }
- else if (ip1.StartsWith("1"))
- {
- if (inputs[0] == "Subnet")
- {
- string binarySubnetNumber = Convert.ToString(int.Parse(inputs[1]), 2);
- string NetworkAdressSubnet = ip1 + "." + ip2;
- for (int a = binarySubnetNumber.Length; a < power; a++)
- {
- NetworkAdressSubnet += "0";
- }
- NetworkAdressSubnet += binarySubnetNumber;
- while (NetworkAdressSubnet.Length < 33)
- {
- NetworkAdressSubnet += "0";
- }
- NetworkAdressSubnet = NetworkAdressSubnet.Insert(17, ".");
- NetworkAdressSubnet = NetworkAdressSubnet.Insert(26, ".");
- List<string> nAS = NetworkAdressSubnet.Split(".").ToList();
- string BroadcastAdressSubnet = ip1 + "." + ip2;
- for (int a = binarySubnetNumber.Length; a < power; a++)
- {
- BroadcastAdressSubnet += "0";
- }
- BroadcastAdressSubnet += binarySubnetNumber;
- while (BroadcastAdressSubnet.Length < 33)
- {
- BroadcastAdressSubnet += "1";
- }
- BroadcastAdressSubnet = BroadcastAdressSubnet.Insert(17, ".");
- BroadcastAdressSubnet = BroadcastAdressSubnet.Insert(26, ".");
- List<string> bNS = BroadcastAdressSubnet.Split(".").ToList();
- Console.WriteLine();
- Console.WriteLine("Network Adress: " + NetworkAdressSubnet);
- Console.WriteLine($"Network Adress: {Convert.ToInt32(nAS[0], 2)}.{Convert.ToInt32(nAS[1], 2)}.{Convert.ToInt32(nAS[2], 2)}.{Convert.ToInt32(nAS[3], 2)}");
- Console.WriteLine();
- Console.WriteLine("Broadcast Adress: " + BroadcastAdressSubnet);
- Console.WriteLine($"Broadcast Adress: {Convert.ToInt32(bNS[0], 2)}.{Convert.ToInt32(bNS[1], 2)}.{Convert.ToInt32(bNS[2], 2)}.{Convert.ToInt32(bNS[3], 2)}");
- Console.WriteLine();
- Console.WriteLine($"Range: {Convert.ToInt32(nAS[0], 2)}.{Convert.ToInt32(nAS[1], 2)}.{Convert.ToInt32(nAS[2], 2)}.{Convert.ToInt32(nAS[3], 2) + 1} to {Convert.ToInt32(bNS[0], 2)}.{Convert.ToInt32(bNS[1], 2)}.{Convert.ToInt32(bNS[2], 2)}.{Convert.ToInt32(bNS[3], 2) - 1}");
- Console.WriteLine("========================================================================================================================");
- }
- }*/
- Console.WriteLine();
- Console.WriteLine("Напишете ip адреса в двоична бройна система: ");
- Console.Write("IP(2): ");
- string inputIPBin = Console.ReadLine();
- Console.WriteLine();
- Console.WriteLine("Определете от кой клас мрежа е ip-то:");
- Console.Write("Network Class: ");
- string inputClass = Console.ReadLine();
- Console.WriteLine();
- Console.WriteLine("Напишете Subnet mask-ата в двоична и десетична бройна система: ");
- Console.Write("Sm(2): ");
- string inputSmBin = Console.ReadLine();
- Console.Write("Sm(10): ");
- string inputSmDec = Console.ReadLine();
- Console.WriteLine();
- Console.WriteLine("Напишете Network Adress-а в двоична и десетична бройна система: ");
- Console.Write("NA(2): ");
- string inputNABin = Console.ReadLine();
- Console.Write("NA(10): ");
- string inputNADec = Console.ReadLine();
- Console.WriteLine();
- Console.WriteLine("Напишете Broadcast Adress-а в двоична и десетична бройна система: ");
- Console.Write("BrA(2): ");
- string inputBrABin = Console.ReadLine();
- Console.Write("BrA(10): ");
- string inputBrADec = Console.ReadLine();
- Console.WriteLine();
- Console.WriteLine("Напишете Range-а в десетична бройна система. На първи ред запишете откъде започва, а на втори - докъде свършва: ");
- Console.Write("Range От: ");
- string inputRangeFrom = Console.ReadLine();
- Console.Write("Range До: ");
- string inputRangeTo = Console.ReadLine();
- Console.WriteLine();
- Console.WriteLine("Напишете Subnet Mask-ата съответстваща на дадения ви брой подмрежи в двоична и десетична бройна система:");
- Console.Write("Sm(2): ");
- string inputSMSubnetBin = Console.ReadLine();
- Console.Write("Sm(10): ");
- string inputSMSubnetDec = Console.ReadLine();
- Console.WriteLine();
- Console.ForegroundColor = ConsoleColor.White;
- Console.WriteLine("------------------------------------------------------------------------------------------------------------------------");
- Console.ForegroundColor = ConsoleColor.Blue;
- Console.WriteLine("Подмрежа № 1");
- Console.ForegroundColor = ConsoleColor.White;
- Console.WriteLine("Напишете Network Adress-а на 1-вата подмрежа в двоична и десетична бройна система: ");
- Console.Write("NA(2): ");
- string inputNABin1 = Console.ReadLine();
- Console.Write("NA(10): ");
- string inputNADec1 = Console.ReadLine();
- Console.WriteLine();
- Console.WriteLine("Напишете Broadcast Adress-а на 1-вата подпрежа в двоична и десетична бройна система: ");
- Console.Write("BrA(2): ");
- string inputBrABin1 = Console.ReadLine();
- Console.Write("BrA(10): ");
- string inputBrADec1 = Console.ReadLine();
- Console.WriteLine();
- Console.WriteLine("Напишете Range-а на 1-вата подмрежа в десетична бройна система. На първи ред запишете откъде започва, а на втори - докъде свършва: ");
- Console.Write("Range От: ");
- string inputRangeFrom1 = Console.ReadLine();
- Console.Write("Range До: ");
- string inputRangeTo1 = Console.ReadLine();
- Console.WriteLine();
- Console.ForegroundColor = ConsoleColor.White;
- Console.WriteLine("------------------------------------------------------------------------------------------------------------------------");
- Console.ForegroundColor = ConsoleColor.Blue;
- Console.WriteLine("Подмрежа № 2");
- Console.ForegroundColor = ConsoleColor.White;
- Console.WriteLine("Напишете Network Adress-а на 2-рата подмрежа в двоична и десетична бройна система: ");
- Console.Write("NA(2): ");
- string inputNABin2 = Console.ReadLine();
- Console.Write("NA(10): ");
- string inputNADec2 = Console.ReadLine();
- Console.WriteLine();
- Console.WriteLine("Напишете Broadcast Adress-а на 2-рата подпрежа в двоична и десетична бройна система: ");
- Console.Write("BrA(2): ");
- string inputBrABin2 = Console.ReadLine();
- Console.Write("BrA(10): ");
- string inputBrADec2 = Console.ReadLine();
- Console.WriteLine();
- Console.WriteLine("Напишете Range-а на 2-рата подмрежа в десетична бройна система. На първи ред запишете откъде започва, а на втори - докъде свършва: ");
- Console.Write("Range От: ");
- string inputRangeFrom2 = Console.ReadLine();
- Console.Write("Range До: ");
- string inputRangeTo2 = Console.ReadLine();
- Console.WriteLine();
- Console.ForegroundColor = ConsoleColor.White;
- Console.WriteLine("------------------------------------------------------------------------------------------------------------------------");
- Console.ForegroundColor = ConsoleColor.Blue;
- Console.WriteLine("Подмрежа № 3");
- Console.ForegroundColor = ConsoleColor.White;
- Console.WriteLine("Напишете Network Adress-а на 3-тата подмрежа в двоична и десетична бройна система: ");
- Console.Write("NA(2): ");
- string inputNABin3 = Console.ReadLine();
- Console.Write("NA(10): ");
- string inputNADec3 = Console.ReadLine();
- Console.WriteLine();
- Console.WriteLine("Напишете Broadcast Adress-а на 3-тата подпрежа в двоична и десетична бройна система: ");
- Console.Write("BrA(2): ");
- string inputBrABin3 = Console.ReadLine();
- Console.Write("BrA(10): ");
- string inputBrADec3 = Console.ReadLine();
- Console.WriteLine();
- Console.WriteLine("Напишете Range-а на 3-тата подмрежа в десетична бройна система. На първи ред запишете откъде започва, а на втори - докъде свършва: ");
- Console.Write("Range От: ");
- string inputRangeFrom3 = Console.ReadLine();
- Console.Write("Range До: ");
- string inputRangeTo3 = Console.ReadLine();
- Console.WriteLine("========================================================================================================================");
- /*Console.WriteLine();
- Console.WriteLine("Напишете Network Adress-а на 1-вата подмрежа в двоична и десетична бройна система: ");
- Console.Write("NA(2): ");
- string inputNABinRandom = Console.ReadLine();
- Console.Write("NA(10): ");
- string inputNADecRandom = Console.ReadLine();
- Console.WriteLine();
- Console.WriteLine("Напишете Broadcast Adress-а на 1-вата подпрежа в двоична и десетична бройна система: ");
- Console.Write("BrA(2): ");
- string inputBrABinRandom = Console.ReadLine();
- Console.Write("BrA(10): ");
- string inputBrADecRandom = Console.ReadLine();
- Console.WriteLine();
- Console.WriteLine("Напишете Range-а на 1вата подмрежа в десетична бройна система. На първи ред запишете откъде започва, а на втори - докъде свършва: ");
- Console.Write("Range От: ");
- string inputRangeFromRandom = Console.ReadLine();
- Console.Write("Range До: ");
- string inputRangeToRandom = Console.ReadLine();*/
- RightAnswerYourAnswer("IP(2) Правилен Отговор: ", "IP(2) Твоят отговор: ", ipBin, inputIPBin);
- NetworkClassAnswer(inputClass, networkClass, networkClassLowerCase);
- RightAnswerYourAnswer("Sm(2) Правилен Отговор: ", "Sm(2) Твоят отговор: ", smBin, inputSmBin);
- RightAnswerYourAnswer("Sm(10) Правилен Отговор: ", "Sm(10) Твоят отговор: ", smDec, inputSmDec);
- RightAnswerYourAnswer("NA(2) Правилен Отговор: ", "NA(2) Твоят отговор: ", naBin, inputNABin);
- RightAnswerYourAnswer("NA(10) Правилен Отговор: ", "NA(10) Твоят отговор: ", naDec, inputNADec);
- RightAnswerYourAnswer("BrA(2) Правилен Отговор: ", "BrA(2) Твоят отговор: ", brABin, inputBrABin);
- RightAnswerYourAnswer("BrA(10) Правилен Отговор: ", "BrA(10) Твоят отговор: ", brADec, inputBrADec);
- RightAnswerYourAnswer("Range От Правилен Отговор: ", "Range От Твоят отговор: ", rangeFrom, inputRangeFrom);
- RightAnswerYourAnswer("Range До Правилен Отговор: ", "Range До Твоят отговор: ", rangeTo, inputRangeTo);
- RightAnswerYourAnswer("Sm(2) Подмрежи Правилен Отговор: ", "Sm(2) Подмрежи Твоят отговор: ", smSubnetBin, inputSMSubnetBin);
- RightAnswerYourAnswer("Sm(10) Подмрежи Правилен Отговор: ", "Sm(10) Подмрежи Твоят отговор: ", smSubnetDec, inputSMSubnetDec);
- Console.ForegroundColor = ConsoleColor.White;
- Console.WriteLine("------------------------------------------------------------------------------------------------------------------------");
- Console.ForegroundColor = ConsoleColor.Blue;
- Console.WriteLine("Подмрежа № 1");
- RightAnswerYourAnswer("NA(2) Правилен Отговор: ", "NA(2) Твоят отговор: ", naBin1, inputNABin1);
- RightAnswerYourAnswer("NA(10) Правилен Отговор: ", "NA(10) Твоят отговор: ", naDec1, inputNADec1);
- RightAnswerYourAnswer("BrA(2) Правилен Отговор: ", "BrA(2) Твоят отговор: ", brABin1, inputBrABin1);
- RightAnswerYourAnswer("BrA(10) Правилен Отговор: ", "BrA(10) Твоят отговор: ", brADec1, inputBrADec1);
- RightAnswerYourAnswer("Range От Правилен Отговор: ", "Range От Твоят отговор: ", rangeFrom1, inputRangeFrom1);
- RightAnswerYourAnswer("Range До Правилен Отговор: ", "Range До Твоят отговор: ", rangeTo1, inputRangeTo1);
- Console.ForegroundColor = ConsoleColor.White;
- Console.WriteLine("------------------------------------------------------------------------------------------------------------------------");
- Console.ForegroundColor = ConsoleColor.Blue;
- Console.WriteLine("Подмрежа № 2");
- RightAnswerYourAnswer("NA(2) Правилен Отговор: ", "NA(2) Твоят отговор: ", naBin2, inputNABin2);
- RightAnswerYourAnswer("NA(10) Правилен Отговор: ", "NA(10) Твоят отговор: ", naDec2, inputNADec2);
- RightAnswerYourAnswer("BrA(2) Правилен Отговор: ", "BrA(2) Твоят отговор: ", brABin2, inputBrABin2);
- RightAnswerYourAnswer("BrA(10) Правилен Отговор: ", "BrA(10) Твоят отговор: ", brADec2, inputBrADec2);
- RightAnswerYourAnswer("Range От Правилен Отговор: ", "Range От Твоят отговор: ", rangeFrom2, inputRangeFrom2);
- RightAnswerYourAnswer("Range До Правилен Отговор: ", "Range До Твоят отговор: ", rangeTo2, inputRangeTo2);
- Console.ForegroundColor = ConsoleColor.White;
- Console.WriteLine("------------------------------------------------------------------------------------------------------------------------");
- Console.ForegroundColor = ConsoleColor.Blue;
- Console.WriteLine("Подмрежа № 3");
- RightAnswerYourAnswer("NA(2) Правилен Отговор: ", "NA(2) Твоят отговор: ", naBin3, inputNABin3);
- RightAnswerYourAnswer("NA(10) Правилен Отговор: ", "NA(10) Твоят отговор: ", naDec3, inputNADec3);
- RightAnswerYourAnswer("BrA(2) Правилен Отговор: ", "BrA(2) Твоят отговор: ", brABin3, inputBrABin3);
- RightAnswerYourAnswer("BrA(10) Правилен Отговор: ", "BrA(10) Твоят отговор: ", brADec3, inputBrADec3);
- RightAnswerYourAnswer("Range От Правилен Отговор: ", "Range От Твоят отговор: ", rangeFrom3, inputRangeFrom3);
- RightAnswerYourAnswer("Range До Правилен Отговор: ", "Range До Твоят отговор: ", rangeTo3, inputRangeTo3);
- Console.ForegroundColor = ConsoleColor.White;
- Console.WriteLine("------------------------------------------------------------------------------------------------------------------------");
- /*Console.WriteLine($"Подмрежа № {random}");
- RightAnswerYourAnswer("NA(2) Правилен Отговор: ", "NA(2) Твоят отговор: ", naBinRandom, inputNABinRandom);
- RightAnswerYourAnswer("NA(10) Правилен Отговор: ", "NA(10) Твоят отговор: ", naDecRandom, inputNADecRandom);
- RightAnswerYourAnswer("BrA(2) Правилен Отговор: ", "BrA(2) Твоят отговор: ", brABinRandom, inputBrABinRandom);
- RightAnswerYourAnswer("BrA(10) Правилен Отговор: ", "BrA(10) Твоят отговор: ", brADecRandom, inputBrADecRandom);
- RightAnswerYourAnswer("Range От Правилен Отговор: ", "Range От Твоят отговор: ", rangeFromRandom, inputRangeFromRandom);
- RightAnswerYourAnswer("Range До Правилен Отговор: ", "Range До Твоят отговор: ", rangeToRandom, inputRangeToRandom);*/
- }
- static string IP(string binary, string ip)
- {
- for (int a = 8; a > binary.Length; a--)
- {
- ip += "0";
- }
- ip += binary;
- return ip;
- }
- static void RightAnswerYourAnswer(string rightAnswerMessage, string YourAnswerMessage, string bin, string inputBin)
- {
- Console.ForegroundColor = ConsoleColor.White;
- Console.Write(rightAnswerMessage);
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine(bin);
- Console.ForegroundColor = ConsoleColor.White;
- Console.Write(YourAnswerMessage);
- if (bin.Length == inputBin.Length)
- {
- for (int a = 0; a < bin.Length; a++)
- {
- if (bin[a] != inputBin[a])
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.Write(inputBin[a]);
- }
- else
- {
- Console.ForegroundColor = ConsoleColor.Green;
- Console.Write(inputBin[a]);
- }
- }
- }
- else if (bin.Length < inputBin.Length)
- {
- for (int a = 0; a < bin.Length; a++)
- {
- if (bin[a] != inputBin[a])
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.Write(inputBin[a]);
- }
- else
- {
- Console.ForegroundColor = ConsoleColor.Green;
- Console.Write(inputBin[a]);
- }
- }
- Console.ForegroundColor = ConsoleColor.Red;
- for (int a = bin.Length; a < inputBin.Length; a++)
- {
- Console.Write(inputBin[a]);
- }
- }
- else if (bin.Length > inputBin.Length)
- {
- for (int a = 0; a < inputBin.Length; a++)
- {
- if (bin[a] != inputBin[a])
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.Write(inputBin[a]);
- }
- else
- {
- Console.ForegroundColor = ConsoleColor.Green;
- Console.Write(inputBin[a]);
- }
- }
- Console.ForegroundColor = ConsoleColor.Red;
- for (int a = inputBin.Length; a < bin.Length; a++)
- {
- Console.Write("-");
- }
- }
- Console.WriteLine();
- Console.WriteLine();
- }
- static void NetworkClassAnswer(string inputClass, string networkClass, string networkClassLowerCase)
- {
- Console.ForegroundColor = ConsoleColor.White;
- Console.Write("Network Class Правилен Отговор: ");
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine(networkClass);
- Console.ForegroundColor = ConsoleColor.White;
- if(inputClass == string.Empty)
- {
- Console.Write("Network Class Твоят Отговор: ");
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("-");
- }
- else if (inputClass == networkClass || inputClass == networkClassLowerCase)
- {
- Console.Write("Network Class Твоят Отговор: ");
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine(inputClass);
- }
- else
- {
- Console.Write("Network Class Твоят Отговор: ");
- Console.ForegroundColor = ConsoleColor.Red;
- Console.Write(inputClass);
- }
- Console.WriteLine();
- }
- static List<string> SubnetMath(int subnetNumber, string naBin, int power, string brABin, string rangeFrom, string rangeTo)
- {
- List<string> outputs = new List<string>();
- string binarySubnetNumber = Convert.ToString(subnetNumber, 2);
- for (int a = binarySubnetNumber.Length; a < power; a++)
- {
- naBin += "0";
- }
- naBin += binarySubnetNumber;
- while (naBin.Length < 34)
- {
- naBin += "0";
- }
- naBin = naBin.Insert(26, ".");
- List<string> naB = brABin.Split(".").ToList();
- for (int a = binarySubnetNumber.Length; a < power; a++)
- {
- brABin += "0";
- }
- brABin += binarySubnetNumber;
- while (brABin.Length < 34)
- {
- brABin += "1";
- }
- brABin = brABin.Insert(26, ".");
- List<string> brB = brABin.Split(".").ToList();
- rangeFrom = $"{Convert.ToInt32(naB[0], 2)}.{Convert.ToInt32(naB[1], 2)}.{Convert.ToInt32(naB[2], 2)}.{Convert.ToInt32(naB[3], 2) + 1}";
- rangeTo = $"{Convert.ToInt32(brB[0], 2)}.{ Convert.ToInt32(brB[1], 2)}.{ Convert.ToInt32(brB[2], 2)}.{Convert.ToInt32(brB[3], 2) - 1}";
- outputs.Add(naBin);
- outputs.Add(brABin);
- outputs.Add(rangeFrom);
- outputs.Add(rangeTo);
- return outputs;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement