Advertisement
XfreeBG

Untitled

Jan 24th, 2023
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 38.27 KB | None | 0 0
  1. Console.OutputEncoding = System.Text.Encoding.UTF8;
  2.             int subnetCount = 0;
  3.             string networkClass = string.Empty;
  4.             string networkClassLowerCase = string.Empty;
  5.             string ipDec = string.Empty;
  6.             string ipBin = string.Empty;
  7.             string smDec = string.Empty;
  8.             string smBin = string.Empty;
  9.             string naDec = string.Empty;
  10.             string naBin = string.Empty;
  11.             string brADec = string.Empty;
  12.             string brABin = string.Empty;
  13.             string rangeFrom = string.Empty;
  14.             string rangeTo = string.Empty;
  15.             string smSubnetDec = string.Empty;
  16.             string smSubnetBin = string.Empty;
  17.  
  18.             string naBin1 = string.Empty;
  19.             string naDec1 = string.Empty;
  20.             string brABin1 = string.Empty;
  21.             string brADec1 = string.Empty;
  22.             string rangeFrom1 = string.Empty;
  23.             string rangeTo1 = string.Empty;
  24.  
  25.             string naBin2 = string.Empty;
  26.             string naDec2 = string.Empty;
  27.             string brABin2 = string.Empty;
  28.             string brADec2 = string.Empty;
  29.             string rangeFrom2 = string.Empty;
  30.             string rangeTo2 = string.Empty;
  31.  
  32.             string naBin3 = string.Empty;
  33.             string naDec3 = string.Empty;
  34.             string brABin3 = string.Empty;
  35.             string brADec3 = string.Empty;
  36.             string rangeFrom3 = string.Empty;
  37.             string rangeTo3 = string.Empty;
  38.  
  39.             string naBinRandom = string.Empty;
  40.             string naDecRandom = string.Empty;
  41.             string brABinRandom = string.Empty;
  42.             string brADecRandom = string.Empty;
  43.             string rangeFromRandom = string.Empty;
  44.             string rangeToRandom = string.Empty;
  45.  
  46.             Console.ForegroundColor = ConsoleColor.White;
  47.             string input = Console.ReadLine();
  48.             input = input.Replace(".", " ");
  49.             List<string> inputs = input.Split(" ").ToList();
  50.  
  51.             string binary1 = Convert.ToString(int.Parse(inputs[0]), 2);
  52.             string binary2 = Convert.ToString(int.Parse(inputs[1]), 2);
  53.             string binary3 = Convert.ToString(int.Parse(inputs[2]), 2);
  54.             string binary4 = Convert.ToString(int.Parse(inputs[3]), 2);
  55.             string ip1 = string.Empty;
  56.             string ip2 = string.Empty;
  57.             string ip3 = string.Empty;
  58.             string ip4 = string.Empty;
  59.  
  60.             ip1 = IP(binary1, ip1);
  61.             ip2 = IP(binary2, ip2);
  62.             ip3 = IP(binary3, ip3);
  63.             ip4 = IP(binary4, ip4);
  64.  
  65.             ipBin = $"{ip1}.{ip2}.{ip3}.{ip4}";
  66.             ipDec = $"{inputs[0]}.{inputs[1]}.{inputs[2]}.{inputs[3]}";
  67.             List<string> iPDec = ipDec.Split(".").ToList();
  68.  
  69.             if (ip1.StartsWith("110"))
  70.             {
  71.                 networkClass = "C";
  72.                 networkClassLowerCase = "c";
  73.  
  74.                 smBin = "11111111.11111111.11111111.00000000";
  75.                 smDec = "255.255.255.0";
  76.  
  77.                 naBin = $"{ip1}.{ip2}.{ip3}.00000000";
  78.                 naDec = $"{inputs[0]}.{inputs[1]}.{inputs[2]}.0";
  79.  
  80.                 brABin = $"{ip1}.{ip2}.{ip3}.11111111";
  81.                 brADec = $"{inputs[0]}.{inputs[1]}.{inputs[2]}.255";
  82.  
  83.                 rangeFrom = $"{inputs[0]}.{inputs[1]}.{inputs[2]}.1 ";
  84.                 rangeTo = $"{inputs[0]}.{inputs[1]}.{inputs[2]}.254";
  85.             }
  86.             else if (ip1.StartsWith("0"))
  87.             {
  88.                 networkClass = "A";
  89.                 networkClassLowerCase = "a";
  90.  
  91.                 smBin = $"11111111.00000000.00000000.00000000";
  92.                 smDec = $"255.0.0.0";
  93.  
  94.                 naBin = $"{ip1}.00000000.00000000.00000000";
  95.                 naDec = $"{inputs[0]}.0.0.0";
  96.  
  97.                 brABin = $"{ip1}.11111111.11111111.11111111";
  98.                 brADec = $"{inputs[0]}.255.255.255";
  99.  
  100.                 rangeFrom = $"{inputs[0]}.0.0.1";
  101.                 rangeTo = $"{inputs[0]}.255.255.254";
  102.             }
  103.             else if (ip1.StartsWith("1"))
  104.             {
  105.                 networkClass = "B";
  106.                 networkClassLowerCase = "b";
  107.  
  108.                 smBin = $"11111111.11111111.00000000.00000000";
  109.                 smDec = $"255.255.0.0";
  110.  
  111.                 naBin = $"{ip1}.{ip2}.00000000.00000000";
  112.                 naDec = $"{inputs[0]}.{inputs[1]}.0.0";
  113.  
  114.                 brABin = $"{ip1}.{ip2}.11111111.11111111";
  115.                 brADec = $"{inputs[0]}.{inputs[1]}.255.255";
  116.  
  117.                 rangeFrom = $"{inputs[0]}.{inputs[1]}.0.1";
  118.                 rangeTo = $"{inputs[0]}.{inputs[1]}.255.254";
  119.             }
  120.  
  121.  
  122.  
  123.             int power = 0;
  124.             subnetCount = int.Parse(inputs[4]);
  125.             while (true)
  126.             {
  127.                     if (int.Parse(iPDec[0]) > 255 || int.Parse(iPDec[1]) > 255 || int.Parse(iPDec[2]) > 255 || int.Parse(iPDec[3]) > 255)
  128.                     {
  129.                         Console.ForegroundColor = ConsoleColor.Red;
  130.                         Console.WriteLine("IP с число над 255, не може да съществува!");
  131.                         Console.ForegroundColor = ConsoleColor.White;
  132.                         input = Console.ReadLine();
  133.                         input = input.Replace(".", " ");
  134.                         iPDec = input.Split(" ").ToList();
  135.                        
  136.  
  137.                     }
  138.                     else if (ip1.StartsWith("110") && subnetCount > 255)
  139.                     {
  140.                         Console.ForegroundColor = ConsoleColor.Red;
  141.                         Console.WriteLine("Не може да се създадат повече от 255 подмрежи с Class C мрежа!");
  142.                         Console.ForegroundColor = ConsoleColor.White;
  143.                         input = Console.ReadLine();
  144.                         input = input.Replace(".", " ");
  145.                         iPDec = input.Split(" ").ToList();
  146.                        
  147.                     }
  148.                     else if (ip1.StartsWith("0") && subnetCount > 16777215)
  149.                     {
  150.                         Console.ForegroundColor = ConsoleColor.Red;
  151.                         Console.WriteLine("Не може да се създадат повече от 16 777 215 подмрежи с Class А мрежа!");
  152.                         Console.ForegroundColor = ConsoleColor.White;
  153.                         input = Console.ReadLine();
  154.                         input = input.Replace(".", " ");
  155.                         iPDec = input.Split(" ").ToList();
  156.                        
  157.                     }
  158.                     else if (ip1.StartsWith("1") && subnetCount > 65535)
  159.                     {
  160.                         Console.ForegroundColor = ConsoleColor.Red;
  161.                         Console.WriteLine("Не може да се създадат повече от 65 535 подмрежи с Class B мрежа!");
  162.                         Console.ForegroundColor = ConsoleColor.White;
  163.                         input = Console.ReadLine();
  164.                         input = input.Replace(".", " ");
  165.                         iPDec = input.Split(" ").ToList();
  166.                        
  167.                     }
  168.                    
  169.                     else
  170.                     {
  171.                         for (int n = 0; n < 25; n++)
  172.                         {
  173.                             if (subnetCount <= Math.Pow(2, n))
  174.                             {
  175.                                 power = n;
  176.                                 break;
  177.                             }
  178.                         }
  179.                         if (ip1.StartsWith("110"))
  180.                         {
  181.                             smSubnetBin = "11111111.11111111.11111111";
  182.                             for (int q = 0; q < power; q++)
  183.                             {
  184.                                 smSubnetBin += "1";
  185.                             }
  186.                             while (smSubnetBin.Length < 34)
  187.                             {
  188.                                 smSubnetBin += "0";
  189.                             }
  190.                             smSubnetBin = smSubnetBin.Insert(26, ".");
  191.                             List<string> sMS = smSubnetBin.Split(".").ToList();
  192.  
  193.                             smSubnetDec = $"{Convert.ToInt32(sMS[0], 2)}.{Convert.ToInt32(sMS[1], 2)}.{Convert.ToInt32(sMS[2], 2)}.{Convert.ToInt32(sMS[3], 2)}";
  194.                         }
  195.                         else if (ip1.StartsWith("0"))
  196.                         {
  197.                             smSubnetBin = "11111111";
  198.                             for (int q = 0; q < power; q++)
  199.                             {
  200.                                 smSubnetBin += "1";
  201.                             }
  202.                             while (smSubnetBin.Length < 32)
  203.                             {
  204.                                 smSubnetBin += "0";
  205.                             }
  206.                             smSubnetBin = smSubnetBin.Insert(8, ".");
  207.                             smSubnetBin = smSubnetBin.Insert(17, ".");
  208.                             smSubnetBin = smSubnetBin.Insert(26, ".");
  209.                             List<string> sMS = smSubnetBin.Split(".").ToList();
  210.  
  211.  
  212.                             smSubnetDec = $"{Convert.ToInt32(sMS[0], 2)}.{Convert.ToInt32(sMS[1], 2)}.{Convert.ToInt32(sMS[2], 2)}.{Convert.ToInt32(sMS[3], 2)}";
  213.                         }
  214.                         else if (ip1.StartsWith("1"))
  215.                         {
  216.                             smSubnetBin = "11111111.11111111";
  217.                             for (int q = 0; q < power; q++)
  218.                             {
  219.                                 smSubnetBin += "1";
  220.                             }
  221.                             while (smSubnetBin.Length < 33)
  222.                             {
  223.                                 smSubnetBin += "0";
  224.                             }
  225.                             smSubnetBin = smSubnetBin.Insert(17, ".");
  226.                             smSubnetBin = smSubnetBin.Insert(26, ".");
  227.                             List<string> sMS = smSubnetBin.Split(".").ToList();
  228.  
  229.                             smSubnetDec = $"{Convert.ToInt32(sMS[0], 2)}.{Convert.ToInt32(sMS[1], 2)}.{Convert.ToInt32(sMS[2], 2)}.{Convert.ToInt32(sMS[3], 2)}";
  230.                         }
  231.                         break;
  232.                     }
  233.                     binary1 = Convert.ToString(int.Parse(iPDec[0]), 2);
  234.                     binary2 = Convert.ToString(int.Parse(iPDec[1]), 2);
  235.                     binary3 = Convert.ToString(int.Parse(iPDec[2]), 2);
  236.                     binary4 = Convert.ToString(int.Parse(iPDec[3]), 2);
  237.                     ip1 = string.Empty;
  238.                     ip2 = string.Empty;
  239.                     ip3 = string.Empty;
  240.                     ip4 = string.Empty;
  241.                     ip1 = IP(binary1, ip1);
  242.                     ip2 = IP(binary2, ip2);
  243.                     ip3 = IP(binary3, ip3);
  244.                     ip4 = IP(binary4, ip4);
  245.                     ipBin = $"{ip1}.{ip2}.{ip3}.{ip4}";
  246.                     subnetCount = int.Parse(iPDec[4]);
  247.  
  248.             }
  249.                 if (ip1.StartsWith("110"))
  250.                 {
  251.                     naBin = ip1 + "." + ip2 + "." + ip3;
  252.                     brABin = ip1 + "." + ip2 + "." + ip3;
  253.                     List<string> subnet1 = SubnetMath(1, naBin ,power, brABin, rangeFrom, rangeTo);
  254.                    
  255.                 }
  256.                
  257.                 /*else if (ip1.StartsWith("0"))
  258.                 {
  259.                     if (inputs[0] == "Subnet")
  260.                     {
  261.                         string binarySubnetNumber = Convert.ToString(int.Parse(inputs[1]), 2);
  262.                         string NetworkAdressSubnet = ip1;
  263.                         for (int a = binarySubnetNumber.Length; a < power; a++)
  264.                         {
  265.                             NetworkAdressSubnet += "0";
  266.                         }
  267.                         NetworkAdressSubnet += binarySubnetNumber;
  268.                         while (NetworkAdressSubnet.Length < 32)
  269.                         {
  270.                             NetworkAdressSubnet += "0";
  271.                         }
  272.                         NetworkAdressSubnet = NetworkAdressSubnet.Insert(8, ".");
  273.                         NetworkAdressSubnet = NetworkAdressSubnet.Insert(17, ".");
  274.                         NetworkAdressSubnet = NetworkAdressSubnet.Insert(26, ".");
  275.                         List<string> nAS = NetworkAdressSubnet.Split(".").ToList();
  276.  
  277.  
  278.                         string BroadcastAdressSubnet = ip1;
  279.                         for (int a = binarySubnetNumber.Length; a < power; a++)
  280.                         {
  281.                             BroadcastAdressSubnet += "0";
  282.                         }
  283.                         BroadcastAdressSubnet += binarySubnetNumber;
  284.                         while (BroadcastAdressSubnet.Length < 32)
  285.                         {
  286.                             BroadcastAdressSubnet += "1";
  287.                         }
  288.                         BroadcastAdressSubnet = BroadcastAdressSubnet.Insert(8, ".");
  289.                         BroadcastAdressSubnet = BroadcastAdressSubnet.Insert(17, ".");
  290.                         BroadcastAdressSubnet = BroadcastAdressSubnet.Insert(26, ".");
  291.                         List<string> bNS = BroadcastAdressSubnet.Split(".").ToList();
  292.  
  293.  
  294.                         Console.WriteLine();
  295.                         Console.WriteLine("Network Adress: " + NetworkAdressSubnet);
  296.                         Console.WriteLine($"Network Adress: {Convert.ToInt32(nAS[0], 2)}.{Convert.ToInt32(nAS[1], 2)}.{Convert.ToInt32(nAS[2], 2)}.{Convert.ToInt32(nAS[3], 2)}");
  297.                         Console.WriteLine();
  298.                         Console.WriteLine("Broadcast Adress: " + BroadcastAdressSubnet);
  299.                         Console.WriteLine($"Broadcast Adress: {Convert.ToInt32(bNS[0], 2)}.{Convert.ToInt32(bNS[1], 2)}.{Convert.ToInt32(bNS[2], 2)}.{Convert.ToInt32(bNS[3], 2)}");
  300.                         Console.WriteLine();
  301.                         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}");
  302.                         Console.WriteLine("========================================================================================================================");
  303.                     }
  304.                 }
  305.                 else if (ip1.StartsWith("1"))
  306.                 {
  307.                     if (inputs[0] == "Subnet")
  308.                     {
  309.                         string binarySubnetNumber = Convert.ToString(int.Parse(inputs[1]), 2);
  310.                         string NetworkAdressSubnet = ip1 + "." + ip2;
  311.                         for (int a = binarySubnetNumber.Length; a < power; a++)
  312.                         {
  313.                             NetworkAdressSubnet += "0";
  314.                         }
  315.                         NetworkAdressSubnet += binarySubnetNumber;
  316.                         while (NetworkAdressSubnet.Length < 33)
  317.                         {
  318.                             NetworkAdressSubnet += "0";
  319.                         }
  320.                         NetworkAdressSubnet = NetworkAdressSubnet.Insert(17, ".");
  321.                         NetworkAdressSubnet = NetworkAdressSubnet.Insert(26, ".");
  322.                         List<string> nAS = NetworkAdressSubnet.Split(".").ToList();
  323.  
  324.  
  325.                         string BroadcastAdressSubnet = ip1 + "." + ip2;
  326.                         for (int a = binarySubnetNumber.Length; a < power; a++)
  327.                         {
  328.                             BroadcastAdressSubnet += "0";
  329.                         }
  330.                         BroadcastAdressSubnet += binarySubnetNumber;
  331.                         while (BroadcastAdressSubnet.Length < 33)
  332.                         {
  333.                             BroadcastAdressSubnet += "1";
  334.                         }
  335.                         BroadcastAdressSubnet = BroadcastAdressSubnet.Insert(17, ".");
  336.                         BroadcastAdressSubnet = BroadcastAdressSubnet.Insert(26, ".");
  337.                         List<string> bNS = BroadcastAdressSubnet.Split(".").ToList();
  338.  
  339.  
  340.                         Console.WriteLine();
  341.                         Console.WriteLine("Network Adress: " + NetworkAdressSubnet);
  342.                         Console.WriteLine($"Network Adress: {Convert.ToInt32(nAS[0], 2)}.{Convert.ToInt32(nAS[1], 2)}.{Convert.ToInt32(nAS[2], 2)}.{Convert.ToInt32(nAS[3], 2)}");
  343.                         Console.WriteLine();
  344.                         Console.WriteLine("Broadcast Adress: " + BroadcastAdressSubnet);
  345.                         Console.WriteLine($"Broadcast Adress: {Convert.ToInt32(bNS[0], 2)}.{Convert.ToInt32(bNS[1], 2)}.{Convert.ToInt32(bNS[2], 2)}.{Convert.ToInt32(bNS[3], 2)}");
  346.                         Console.WriteLine();
  347.                         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}");
  348.                         Console.WriteLine("========================================================================================================================");
  349.                     }
  350.                 }*/
  351.            
  352.  
  353.             Console.WriteLine();
  354.             Console.WriteLine("Напишете ip адреса в двоична бройна система: ");
  355.             Console.Write("IP(2): ");
  356.             string inputIPBin = Console.ReadLine();
  357.  
  358.             Console.WriteLine();
  359.             Console.WriteLine("Определете от кой клас мрежа е ip-то:");
  360.             Console.Write("Network Class: ");
  361.             string inputClass = Console.ReadLine();
  362.  
  363.             Console.WriteLine();
  364.             Console.WriteLine("Напишете Subnet mask-ата в двоична и десетична бройна система: ");
  365.             Console.Write("Sm(2): ");
  366.             string inputSmBin = Console.ReadLine();
  367.             Console.Write("Sm(10): ");
  368.             string inputSmDec = Console.ReadLine();
  369.  
  370.             Console.WriteLine();
  371.             Console.WriteLine("Напишете Network Adress-а в двоична и десетична бройна система: ");
  372.             Console.Write("NA(2): ");
  373.             string inputNABin = Console.ReadLine();
  374.             Console.Write("NA(10): ");
  375.             string inputNADec = Console.ReadLine();
  376.  
  377.             Console.WriteLine();
  378.             Console.WriteLine("Напишете Broadcast Adress-а в двоична и десетична бройна система: ");
  379.             Console.Write("BrA(2): ");
  380.             string inputBrABin = Console.ReadLine();
  381.             Console.Write("BrA(10): ");
  382.             string inputBrADec = Console.ReadLine();
  383.  
  384.             Console.WriteLine();
  385.             Console.WriteLine("Напишете Range-а в десетична бройна система. На първи ред запишете откъде започва, а на втори - докъде свършва: ");
  386.             Console.Write("Range От: ");
  387.             string inputRangeFrom = Console.ReadLine();
  388.             Console.Write("Range До: ");
  389.             string inputRangeTo = Console.ReadLine();
  390.  
  391.             Console.WriteLine();
  392.             Console.WriteLine("Напишете Subnet Mask-ата съответстваща на дадения ви брой подмрежи в двоична и десетична бройна система:");
  393.             Console.Write("Sm(2): ");
  394.             string inputSMSubnetBin = Console.ReadLine();
  395.             Console.Write("Sm(10): ");
  396.             string inputSMSubnetDec = Console.ReadLine();
  397.  
  398.  
  399.  
  400.             Console.WriteLine();
  401.             Console.ForegroundColor = ConsoleColor.White;
  402.             Console.WriteLine("------------------------------------------------------------------------------------------------------------------------");
  403.             Console.ForegroundColor = ConsoleColor.Blue;
  404.             Console.WriteLine("Подмрежа № 1");
  405.             Console.ForegroundColor = ConsoleColor.White;
  406.             Console.WriteLine("Напишете Network Adress-а на 1-вата подмрежа в двоична и десетична бройна система: ");
  407.             Console.Write("NA(2): ");
  408.             string inputNABin1 = Console.ReadLine();
  409.             Console.Write("NA(10): ");
  410.             string inputNADec1 = Console.ReadLine();
  411.  
  412.             Console.WriteLine();
  413.             Console.WriteLine("Напишете Broadcast Adress-а на 1-вата подпрежа в двоична и десетична бройна система: ");
  414.             Console.Write("BrA(2): ");
  415.             string inputBrABin1 = Console.ReadLine();
  416.             Console.Write("BrA(10): ");
  417.             string inputBrADec1 = Console.ReadLine();
  418.  
  419.             Console.WriteLine();
  420.             Console.WriteLine("Напишете Range-а на 1-вата подмрежа в десетична бройна система. На първи ред запишете откъде започва, а на втори - докъде свършва: ");
  421.             Console.Write("Range От: ");
  422.             string inputRangeFrom1 = Console.ReadLine();
  423.             Console.Write("Range До: ");
  424.             string inputRangeTo1 = Console.ReadLine();
  425.  
  426.  
  427.  
  428.  
  429.             Console.WriteLine();
  430.             Console.ForegroundColor = ConsoleColor.White;
  431.             Console.WriteLine("------------------------------------------------------------------------------------------------------------------------");
  432.             Console.ForegroundColor = ConsoleColor.Blue;
  433.             Console.WriteLine("Подмрежа № 2");
  434.             Console.ForegroundColor = ConsoleColor.White;
  435.             Console.WriteLine("Напишете Network Adress-а на 2-рата подмрежа в двоична и десетична бройна система: ");
  436.             Console.Write("NA(2): ");
  437.             string inputNABin2 = Console.ReadLine();
  438.             Console.Write("NA(10): ");
  439.             string inputNADec2 = Console.ReadLine();
  440.  
  441.             Console.WriteLine();
  442.             Console.WriteLine("Напишете Broadcast Adress-а на 2-рата подпрежа в двоична и десетична бройна система: ");
  443.             Console.Write("BrA(2): ");
  444.             string inputBrABin2 = Console.ReadLine();
  445.             Console.Write("BrA(10): ");
  446.             string inputBrADec2 = Console.ReadLine();
  447.  
  448.             Console.WriteLine();
  449.             Console.WriteLine("Напишете Range-а на 2-рата подмрежа в десетична бройна система. На първи ред запишете откъде започва, а на втори - докъде свършва: ");
  450.             Console.Write("Range От: ");
  451.             string inputRangeFrom2 = Console.ReadLine();
  452.             Console.Write("Range До: ");
  453.             string inputRangeTo2 = Console.ReadLine();
  454.  
  455.  
  456.  
  457.             Console.WriteLine();
  458.             Console.ForegroundColor = ConsoleColor.White;
  459.             Console.WriteLine("------------------------------------------------------------------------------------------------------------------------");
  460.             Console.ForegroundColor = ConsoleColor.Blue;
  461.             Console.WriteLine("Подмрежа № 3");
  462.             Console.ForegroundColor = ConsoleColor.White;
  463.             Console.WriteLine("Напишете Network Adress-а на 3-тата подмрежа в двоична и десетична бройна система: ");
  464.             Console.Write("NA(2): ");
  465.             string inputNABin3 = Console.ReadLine();
  466.             Console.Write("NA(10): ");
  467.             string inputNADec3 = Console.ReadLine();
  468.  
  469.             Console.WriteLine();
  470.             Console.WriteLine("Напишете Broadcast Adress-а на 3-тата подпрежа в двоична и десетична бройна система: ");
  471.             Console.Write("BrA(2): ");
  472.             string inputBrABin3 = Console.ReadLine();
  473.             Console.Write("BrA(10): ");
  474.             string inputBrADec3 = Console.ReadLine();
  475.  
  476.             Console.WriteLine();
  477.             Console.WriteLine("Напишете Range-а на 3-тата подмрежа в десетична бройна система. На първи ред запишете откъде започва, а на втори - докъде свършва: ");
  478.             Console.Write("Range От: ");
  479.             string inputRangeFrom3 = Console.ReadLine();
  480.             Console.Write("Range До: ");
  481.             string inputRangeTo3 = Console.ReadLine();
  482.             Console.WriteLine("========================================================================================================================");
  483.            
  484.  
  485.  
  486.             /*Console.WriteLine();
  487.             Console.WriteLine("Напишете Network Adress-а на 1-вата подмрежа в двоична и десетична бройна система: ");
  488.             Console.Write("NA(2): ");
  489.             string inputNABinRandom = Console.ReadLine();
  490.             Console.Write("NA(10): ");
  491.             string inputNADecRandom = Console.ReadLine();
  492.  
  493.             Console.WriteLine();
  494.             Console.WriteLine("Напишете Broadcast Adress-а на 1-вата подпрежа в двоична и десетична бройна система: ");
  495.             Console.Write("BrA(2): ");
  496.             string inputBrABinRandom = Console.ReadLine();
  497.             Console.Write("BrA(10): ");
  498.             string inputBrADecRandom = Console.ReadLine();
  499.  
  500.             Console.WriteLine();
  501.             Console.WriteLine("Напишете Range-а на 1вата подмрежа в десетична бройна система. На първи ред запишете откъде започва, а на втори - докъде свършва: ");
  502.             Console.Write("Range От: ");
  503.             string inputRangeFromRandom = Console.ReadLine();
  504.             Console.Write("Range До: ");
  505.             string inputRangeToRandom = Console.ReadLine();*/
  506.  
  507.  
  508.  
  509.             RightAnswerYourAnswer("IP(2) Правилен Отговор: ", "IP(2) Твоят отговор:    ",  ipBin, inputIPBin);
  510.             NetworkClassAnswer(inputClass, networkClass, networkClassLowerCase);
  511.             RightAnswerYourAnswer("Sm(2) Правилен Отговор: ", "Sm(2) Твоят отговор:    ", smBin, inputSmBin);
  512.             RightAnswerYourAnswer("Sm(10) Правилен Отговор: ", "Sm(10) Твоят отговор:    ", smDec, inputSmDec);
  513.             RightAnswerYourAnswer("NA(2) Правилен Отговор: ", "NA(2) Твоят отговор:    ", naBin, inputNABin);
  514.             RightAnswerYourAnswer("NA(10) Правилен Отговор: ", "NA(10) Твоят отговор:    ", naDec, inputNADec);
  515.             RightAnswerYourAnswer("BrA(2) Правилен Отговор: ", "BrA(2) Твоят отговор:    ", brABin, inputBrABin);
  516.             RightAnswerYourAnswer("BrA(10) Правилен Отговор: ", "BrA(10) Твоят отговор:    ", brADec, inputBrADec);
  517.             RightAnswerYourAnswer("Range От Правилен Отговор: ", "Range От Твоят отговор:    ", rangeFrom, inputRangeFrom);
  518.             RightAnswerYourAnswer("Range До Правилен Отговор: ", "Range До Твоят отговор:    ", rangeTo, inputRangeTo);
  519.             RightAnswerYourAnswer("Sm(2) Подмрежи Правилен Отговор:  ", "Sm(2) Подмрежи Твоят отговор:     ", smSubnetBin, inputSMSubnetBin);
  520.             RightAnswerYourAnswer("Sm(10) Подмрежи Правилен Отговор: ", "Sm(10) Подмрежи Твоят отговор:    ", smSubnetDec, inputSMSubnetDec);
  521.  
  522.             Console.ForegroundColor = ConsoleColor.White;
  523.             Console.WriteLine("------------------------------------------------------------------------------------------------------------------------");
  524.             Console.ForegroundColor = ConsoleColor.Blue;
  525.             Console.WriteLine("Подмрежа № 1");
  526.             RightAnswerYourAnswer("NA(2) Правилен Отговор: ", "NA(2) Твоят отговор:    ", naBin1, inputNABin1);
  527.             RightAnswerYourAnswer("NA(10) Правилен Отговор: ", "NA(10) Твоят отговор:    ", naDec1, inputNADec1);
  528.             RightAnswerYourAnswer("BrA(2) Правилен Отговор: ", "BrA(2) Твоят отговор:    ", brABin1, inputBrABin1);
  529.             RightAnswerYourAnswer("BrA(10) Правилен Отговор: ", "BrA(10) Твоят отговор:    ", brADec1, inputBrADec1);
  530.             RightAnswerYourAnswer("Range От Правилен Отговор: ", "Range От Твоят отговор:    ", rangeFrom1, inputRangeFrom1);
  531.             RightAnswerYourAnswer("Range До Правилен Отговор: ", "Range До Твоят отговор:    ", rangeTo1, inputRangeTo1);
  532.  
  533.             Console.ForegroundColor = ConsoleColor.White;
  534.             Console.WriteLine("------------------------------------------------------------------------------------------------------------------------");
  535.             Console.ForegroundColor = ConsoleColor.Blue;
  536.             Console.WriteLine("Подмрежа № 2");
  537.             RightAnswerYourAnswer("NA(2) Правилен Отговор: ", "NA(2) Твоят отговор:    ", naBin2, inputNABin2);
  538.             RightAnswerYourAnswer("NA(10) Правилен Отговор: ", "NA(10) Твоят отговор:    ", naDec2, inputNADec2);
  539.             RightAnswerYourAnswer("BrA(2) Правилен Отговор: ", "BrA(2) Твоят отговор:    ", brABin2, inputBrABin2);
  540.             RightAnswerYourAnswer("BrA(10) Правилен Отговор: ", "BrA(10) Твоят отговор:    ", brADec2, inputBrADec2);
  541.             RightAnswerYourAnswer("Range От Правилен Отговор: ", "Range От Твоят отговор:    ", rangeFrom2, inputRangeFrom2);
  542.             RightAnswerYourAnswer("Range До Правилен Отговор: ", "Range До Твоят отговор:    ", rangeTo2, inputRangeTo2);
  543.  
  544.             Console.ForegroundColor = ConsoleColor.White;
  545.             Console.WriteLine("------------------------------------------------------------------------------------------------------------------------");
  546.             Console.ForegroundColor = ConsoleColor.Blue;
  547.             Console.WriteLine("Подмрежа № 3");
  548.             RightAnswerYourAnswer("NA(2) Правилен Отговор: ", "NA(2) Твоят отговор:    ", naBin3, inputNABin3);
  549.             RightAnswerYourAnswer("NA(10) Правилен Отговор: ", "NA(10) Твоят отговор:    ", naDec3, inputNADec3);
  550.             RightAnswerYourAnswer("BrA(2) Правилен Отговор: ", "BrA(2) Твоят отговор:    ", brABin3, inputBrABin3);
  551.             RightAnswerYourAnswer("BrA(10) Правилен Отговор: ", "BrA(10) Твоят отговор:    ", brADec3, inputBrADec3);
  552.             RightAnswerYourAnswer("Range От Правилен Отговор: ", "Range От Твоят отговор:    ", rangeFrom3, inputRangeFrom3);
  553.             RightAnswerYourAnswer("Range До Правилен Отговор: ", "Range До Твоят отговор:    ", rangeTo3, inputRangeTo3);
  554.  
  555.             Console.ForegroundColor = ConsoleColor.White;
  556.             Console.WriteLine("------------------------------------------------------------------------------------------------------------------------");
  557.             /*Console.WriteLine($"Подмрежа № {random}");
  558.             RightAnswerYourAnswer("NA(2) Правилен Отговор: ", "NA(2) Твоят отговор:    ", naBinRandom, inputNABinRandom);
  559.             RightAnswerYourAnswer("NA(10) Правилен Отговор: ", "NA(10) Твоят отговор:    ", naDecRandom, inputNADecRandom);
  560.             RightAnswerYourAnswer("BrA(2) Правилен Отговор: ", "BrA(2) Твоят отговор:    ", brABinRandom, inputBrABinRandom);
  561.             RightAnswerYourAnswer("BrA(10) Правилен Отговор: ", "BrA(10) Твоят отговор:    ", brADecRandom, inputBrADecRandom);
  562.             RightAnswerYourAnswer("Range От Правилен Отговор: ", "Range От Твоят отговор:    ", rangeFromRandom, inputRangeFromRandom);
  563.             RightAnswerYourAnswer("Range До Правилен Отговор: ", "Range До Твоят отговор:    ", rangeToRandom, inputRangeToRandom);*/
  564.  
  565.         }
  566.  
  567.         static string IP(string binary, string ip)
  568.         {
  569.             for (int a = 8; a > binary.Length; a--)
  570.             {
  571.                 ip += "0";
  572.             }
  573.             ip += binary;
  574.             return ip;
  575.         }
  576.         static void RightAnswerYourAnswer(string rightAnswerMessage, string YourAnswerMessage, string bin, string inputBin)
  577.         {
  578.             Console.ForegroundColor = ConsoleColor.White;
  579.             Console.Write(rightAnswerMessage);
  580.             Console.ForegroundColor = ConsoleColor.Green;
  581.             Console.WriteLine(bin);
  582.             Console.ForegroundColor = ConsoleColor.White;
  583.             Console.Write(YourAnswerMessage);
  584.  
  585.             if (bin.Length == inputBin.Length)
  586.             {
  587.                 for (int a = 0; a < bin.Length; a++)
  588.                 {
  589.                     if (bin[a] != inputBin[a])
  590.                     {
  591.                         Console.ForegroundColor = ConsoleColor.Red;
  592.                         Console.Write(inputBin[a]);
  593.                     }
  594.                     else
  595.                     {
  596.                         Console.ForegroundColor = ConsoleColor.Green;
  597.                         Console.Write(inputBin[a]);
  598.                     }
  599.                 }
  600.             }
  601.             else if (bin.Length < inputBin.Length)
  602.             {
  603.                 for (int a = 0; a < bin.Length; a++)
  604.                 {
  605.                     if (bin[a] != inputBin[a])
  606.                     {
  607.                         Console.ForegroundColor = ConsoleColor.Red;
  608.                         Console.Write(inputBin[a]);
  609.                     }
  610.                     else
  611.                     {
  612.                         Console.ForegroundColor = ConsoleColor.Green;
  613.                         Console.Write(inputBin[a]);
  614.                     }
  615.                 }
  616.                 Console.ForegroundColor = ConsoleColor.Red;
  617.                 for (int a = bin.Length; a < inputBin.Length; a++)
  618.                 {
  619.                     Console.Write(inputBin[a]);
  620.                 }
  621.             }
  622.             else if (bin.Length > inputBin.Length)
  623.             {
  624.                 for (int a = 0; a < inputBin.Length; a++)
  625.                 {
  626.                     if (bin[a] != inputBin[a])
  627.                     {
  628.                         Console.ForegroundColor = ConsoleColor.Red;
  629.                         Console.Write(inputBin[a]);
  630.                     }
  631.                     else
  632.                     {
  633.                         Console.ForegroundColor = ConsoleColor.Green;
  634.                         Console.Write(inputBin[a]);
  635.                     }
  636.                 }
  637.                 Console.ForegroundColor = ConsoleColor.Red;
  638.                 for (int a = inputBin.Length; a < bin.Length; a++)
  639.                 {
  640.                     Console.Write("-");
  641.                 }
  642.             }
  643.             Console.WriteLine();
  644.             Console.WriteLine();
  645.         }
  646.  
  647.         static void NetworkClassAnswer(string inputClass, string networkClass, string networkClassLowerCase)
  648.         {
  649.             Console.ForegroundColor = ConsoleColor.White;
  650.             Console.Write("Network Class Правилен Отговор: ");
  651.             Console.ForegroundColor = ConsoleColor.Green;
  652.             Console.WriteLine(networkClass);
  653.             Console.ForegroundColor = ConsoleColor.White;
  654.             if(inputClass == string.Empty)
  655.             {  
  656.                 Console.Write("Network Class Твоят Отговор:    ");
  657.                 Console.ForegroundColor = ConsoleColor.Red;
  658.                 Console.WriteLine("-");
  659.             }
  660.             else if (inputClass == networkClass || inputClass == networkClassLowerCase)
  661.             {                
  662.                 Console.Write("Network Class Твоят Отговор:    ");
  663.                 Console.ForegroundColor = ConsoleColor.Green;
  664.                 Console.WriteLine(inputClass);
  665.             }
  666.             else
  667.             {
  668.  
  669.                 Console.Write("Network Class Твоят Отговор:    ");
  670.                 Console.ForegroundColor = ConsoleColor.Red;
  671.                 Console.Write(inputClass);
  672.             }
  673.             Console.WriteLine();
  674.         }
  675.         static List<string> SubnetMath(int subnetNumber, string naBin, int power, string brABin, string rangeFrom, string rangeTo)
  676.         {
  677.             List<string> outputs = new List<string>();
  678.             string binarySubnetNumber = Convert.ToString(subnetNumber, 2);
  679.  
  680.             for (int a = binarySubnetNumber.Length; a < power; a++)
  681.             {
  682.                 naBin += "0";
  683.             }
  684.             naBin += binarySubnetNumber;
  685.             while (naBin.Length < 34)
  686.             {
  687.                 naBin += "0";
  688.             }
  689.             naBin = naBin.Insert(26, ".");
  690.             List<string> naB = brABin.Split(".").ToList();
  691.  
  692.             for (int a = binarySubnetNumber.Length; a < power; a++)
  693.             {
  694.                 brABin += "0";
  695.             }
  696.             brABin += binarySubnetNumber;
  697.             while (brABin.Length < 34)
  698.             {
  699.                 brABin += "1";
  700.             }
  701.             brABin = brABin.Insert(26, ".");
  702.             List<string> brB = brABin.Split(".").ToList();
  703.  
  704.             rangeFrom = $"{Convert.ToInt32(naB[0], 2)}.{Convert.ToInt32(naB[1], 2)}.{Convert.ToInt32(naB[2], 2)}.{Convert.ToInt32(naB[3], 2) + 1}";
  705.             rangeTo = $"{Convert.ToInt32(brB[0], 2)}.{ Convert.ToInt32(brB[1], 2)}.{ Convert.ToInt32(brB[2], 2)}.{Convert.ToInt32(brB[3], 2) - 1}";
  706.             outputs.Add(naBin);
  707.             outputs.Add(brABin);
  708.             outputs.Add(rangeFrom);
  709.             outputs.Add(rangeTo);
  710.             return outputs;
  711.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement