Advertisement
XfreeBG

Untitled

Jan 18th, 2023
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 19.25 KB | None | 0 0
  1. Console.ForegroundColor = ConsoleColor.White;
  2.             string input = Console.ReadLine();
  3.             List<string> inputs = input.Split(".").ToList();
  4.  
  5.             string binary1 = Convert.ToString(int.Parse(inputs[0]), 2);
  6.             string binary2 = Convert.ToString(int.Parse(inputs[1]), 2);
  7.             string binary3 = Convert.ToString(int.Parse(inputs[2]), 2);
  8.             string binary4 = Convert.ToString(int.Parse(inputs[3]), 2);
  9.             string ip1 = string.Empty;
  10.             string ip2 = string.Empty;
  11.             string ip3 = string.Empty;
  12.             string ip4 = string.Empty;
  13.  
  14.             for (int a = 8; a > binary1.Length; a--)
  15.             {
  16.                 ip1 += "0";
  17.             }
  18.             ip1 += binary1;
  19.  
  20.             for (int a = 8; a > binary2.Length; a--)
  21.             {
  22.                 ip2 += "0";
  23.             }
  24.             ip2 += binary2;
  25.  
  26.             for (int a = 8; a > binary3.Length; a--)
  27.             {
  28.                 ip3 += "0";
  29.             }
  30.             ip3 += binary3;
  31.  
  32.             for (int a = 8; a > binary4.Length; a--)
  33.             {
  34.                 ip4 += "0";
  35.             }
  36.             ip4 += binary4;
  37.  
  38.             Console.WriteLine("========================================================================================================================");
  39.             Console.WriteLine($"IP: {ip1}.{ip2}.{ip3}.{ip4}");
  40.             Console.WriteLine("IP: " + input);
  41.             Console.WriteLine();
  42.  
  43.             if (ip1.StartsWith("110"))
  44.             {
  45.                 Console.WriteLine("Network: Class C");
  46.                 Console.WriteLine();
  47.  
  48.                 Console.WriteLine($"Subnet Mask: 11111111.11111111.11111111.00000000");
  49.                 Console.WriteLine($"Subnet Mask: 255.255.255.0");
  50.                 Console.WriteLine();
  51.  
  52.                 Console.WriteLine($"Network Adress: {ip1}.{ip2}.{ip3}.00000000");
  53.                 Console.WriteLine($"Network Adress: {inputs[0]}.{inputs[1]}.{inputs[2]}.0");
  54.                 Console.WriteLine();
  55.  
  56.                 Console.WriteLine($"Broadcast Adress: {ip1}.{ip2}.{ip3}.11111111");
  57.                 Console.WriteLine($"Broadcast Adress: {inputs[0]}.{inputs[1]}.{inputs[2]}.255");
  58.                 Console.WriteLine();
  59.  
  60.                 Console.WriteLine($"Range: {inputs[0]}.{inputs[1]}.{inputs[2]}.1 to {inputs[0]}.{inputs[1]}.{inputs[2]}.254");
  61.             }
  62.             else if (ip1.StartsWith("0"))
  63.             {
  64.                 Console.WriteLine("Network: Class A");
  65.                 Console.WriteLine();
  66.  
  67.                 Console.WriteLine($"Subnet Mask: 11111111.00000000.00000000.00000000");
  68.                 Console.WriteLine($"Subnet Mask: 255.0.0.0");
  69.                 Console.WriteLine();
  70.  
  71.                 Console.WriteLine($"Network Adress: {ip1}.00000000.00000000.00000000");
  72.                 Console.WriteLine($"Network Adress: {inputs[0]}.0.0.0");
  73.                 Console.WriteLine();
  74.  
  75.                 Console.WriteLine($"Broadcast Adress: {ip1}.11111111.11111111.11111111");
  76.                 Console.WriteLine($"Broadcast Adress: {inputs[0]}.255.255.255");
  77.                 Console.WriteLine();
  78.  
  79.                 Console.WriteLine($"Range: {inputs[0]}.0.0.1 to {inputs[0]}.255.255.254");
  80.             }
  81.             else if (ip1.StartsWith("1"))
  82.             {
  83.                 Console.WriteLine("Network: Class B");
  84.                 Console.WriteLine();
  85.  
  86.                 Console.WriteLine($"Subnet Mask: 11111111.11111111.00000000.00000000");
  87.                 Console.WriteLine($"Subnet Mask: 255.255.0.0");
  88.                 Console.WriteLine();
  89.  
  90.                 Console.WriteLine($"Network Adress: {ip1}.{ip2}.00000000.00000000");
  91.                 Console.WriteLine($"Network Adress: {inputs[0]}.{inputs[1]}.0.0");
  92.                 Console.WriteLine();
  93.  
  94.                 Console.WriteLine($"Broadcast Adress: {ip1}.{ip2}.11111111.11111111");
  95.                 Console.WriteLine($"Broadcast Adress: {inputs[0]}.{inputs[1]}.255.255");
  96.                 Console.WriteLine();
  97.  
  98.                 Console.WriteLine($"Range: {inputs[0]}.{inputs[1]}.0.1 to {inputs[0]}.{inputs[1]}.255.254");
  99.             }
  100.             Console.WriteLine("========================================================================================================================");
  101.             int power = 0;
  102.             input = Console.ReadLine();
  103.             while (true)
  104.             {
  105.                 inputs = input.Split(" ").ToList();
  106.                 int SubnetCount = int.Parse(inputs[1]);
  107.  
  108.                 if (inputs[0] == "CreateSubnet")
  109.                 {
  110.                     if (ip1.StartsWith("110") && SubnetCount > 255)
  111.                     {
  112.                         Console.ForegroundColor = ConsoleColor.Red;
  113.                         Console.WriteLine("Cannot create more than 255 subnets with Class C network!");
  114.                         Console.ForegroundColor = ConsoleColor.White;
  115.                         input = Console.ReadLine();
  116.                     }
  117.                     else if (ip1.StartsWith("0") && SubnetCount > 16777215)
  118.                     {
  119.                         Console.ForegroundColor = ConsoleColor.Red;
  120.                         Console.WriteLine("Cannot create more than 16 777 215 subnets with Class A network!");
  121.                         Console.ForegroundColor = ConsoleColor.White;
  122.                         input = Console.ReadLine();
  123.                     }
  124.                     else if (ip1.StartsWith("1") && SubnetCount > 65535)
  125.                     {
  126.                         Console.ForegroundColor = ConsoleColor.Red;
  127.                         Console.WriteLine("Cannot create more than 65 535 subnets with Class B network!");
  128.                         Console.ForegroundColor = ConsoleColor.White;
  129.                         input = Console.ReadLine();
  130.                     }
  131.                     else
  132.                     {
  133.                         for (int n = 0; n < 25; n++)
  134.                         {
  135.                             if (SubnetCount <= Math.Pow(2, n))
  136.                             {
  137.                                 power = n;
  138.                                 break;
  139.                             }
  140.                         }
  141.                         if (ip1.StartsWith("110"))
  142.                         {
  143.                             string subnetMaskSubnet = "11111111.11111111.11111111";
  144.                             for (int q = 0; q < power; q++)
  145.                             {
  146.                                 subnetMaskSubnet += "1";
  147.                             }
  148.                             while (subnetMaskSubnet.Length < 34)
  149.                             {
  150.                                 subnetMaskSubnet += "0";
  151.                             }
  152.                             subnetMaskSubnet = subnetMaskSubnet.Insert(26, ".");
  153.                             List<string> sMS = subnetMaskSubnet.Split(".").ToList();
  154.  
  155.                             Console.WriteLine();
  156.                             Console.WriteLine("Subnet Mask: " + subnetMaskSubnet);
  157.                             Console.WriteLine($"Subnet Mask: {Convert.ToInt32(sMS[0], 2)}.{Convert.ToInt32(sMS[1], 2)}.{Convert.ToInt32(sMS[2], 2)}.{Convert.ToInt32(sMS[3], 2)}");
  158.                             Console.WriteLine("========================================================================================================================");
  159.                         }
  160.                         else if (ip1.StartsWith("0"))
  161.                         {
  162.                             string subnetMaskSubnet = "11111111";
  163.                             for (int q = 0; q < power; q++)
  164.                             {
  165.                                 subnetMaskSubnet += "1";
  166.                             }
  167.                             while (subnetMaskSubnet.Length < 32)
  168.                             {
  169.                                 subnetMaskSubnet += "0";
  170.                             }
  171.                             subnetMaskSubnet = subnetMaskSubnet.Insert(8, ".");
  172.                             subnetMaskSubnet = subnetMaskSubnet.Insert(17, ".");
  173.                             subnetMaskSubnet = subnetMaskSubnet.Insert(26, ".");
  174.                             List<string> sMS = subnetMaskSubnet.Split(".").ToList();
  175.  
  176.                             Console.WriteLine();
  177.                             Console.WriteLine("Subnet Mask: " + subnetMaskSubnet);
  178.                             Console.WriteLine($"Subnet Mask: {Convert.ToInt32(sMS[0], 2)}.{Convert.ToInt32(sMS[1], 2)}.{Convert.ToInt32(sMS[2], 2)}.{Convert.ToInt32(sMS[3], 2)}");
  179.                             Console.WriteLine("========================================================================================================================");
  180.                         }
  181.                         else if (ip1.StartsWith("1"))
  182.                         {
  183.                             string subnetMaskSubnet = "11111111.11111111";
  184.                             for (int q = 0; q < power; q++)
  185.                             {
  186.                                 subnetMaskSubnet += "1";
  187.                             }
  188.                             while (subnetMaskSubnet.Length < 33)
  189.                             {
  190.                                 subnetMaskSubnet += "0";
  191.                             }
  192.                             subnetMaskSubnet = subnetMaskSubnet.Insert(17, ".");
  193.                             subnetMaskSubnet = subnetMaskSubnet.Insert(26, ".");
  194.                             List<string> sMS = subnetMaskSubnet.Split(".").ToList();
  195.  
  196.                             Console.WriteLine();
  197.                             Console.WriteLine("Subnet Mask: " + subnetMaskSubnet);
  198.                             Console.WriteLine($"Subnet Mask: {Convert.ToInt32(sMS[0], 2)}.{Convert.ToInt32(sMS[1], 2)}.{Convert.ToInt32(sMS[2], 2)}.{Convert.ToInt32(sMS[3], 2)}");
  199.                             Console.WriteLine("========================================================================================================================");
  200.                         }
  201.                         break;
  202.                     }
  203.                 }              
  204.             }            
  205.             while (true)
  206.             {
  207.                 input = Console.ReadLine();
  208.                 inputs = input.Split(" ").ToList();
  209.                 if (ip1.StartsWith("110"))
  210.                 {
  211.                     if (inputs[0] == "Subnet")
  212.                     {
  213.                         string binarySubnetNumber = Convert.ToString(int.Parse(inputs[1]), 2);
  214.                         string NetworkAdressSubnet = ip1 + "." + ip2 + "." + ip3;
  215.                         for (int a = binarySubnetNumber.Length; a < power; a++)
  216.                         {
  217.                             NetworkAdressSubnet += "0";
  218.                         }
  219.                         NetworkAdressSubnet += binarySubnetNumber;
  220.                         while (NetworkAdressSubnet.Length < 34)
  221.                         {
  222.                             NetworkAdressSubnet += "0";
  223.                         }
  224.                         NetworkAdressSubnet = NetworkAdressSubnet.Insert(26, ".");
  225.                         List<string> nAS = NetworkAdressSubnet.Split(".").ToList();
  226.  
  227.  
  228.                         string BroadcastAdressSubnet = ip1 + "." + ip2 + "." + ip3;
  229.                         for (int a = binarySubnetNumber.Length; a < power; a++)
  230.                         {
  231.                             BroadcastAdressSubnet += "0";
  232.                         }
  233.                         BroadcastAdressSubnet += binarySubnetNumber;
  234.                         while (BroadcastAdressSubnet.Length < 34)
  235.                         {
  236.                             BroadcastAdressSubnet += "1";
  237.                         }
  238.                         BroadcastAdressSubnet = BroadcastAdressSubnet.Insert(26, ".");
  239.                         List<string> bNS = BroadcastAdressSubnet.Split(".").ToList();
  240.  
  241.                        
  242.                         Console.WriteLine();
  243.                         Console.WriteLine("Network Adress: " + NetworkAdressSubnet);
  244.                         Console.WriteLine($"Network Adress: {Convert.ToInt32(nAS[0], 2)}.{Convert.ToInt32(nAS[1], 2)}.{Convert.ToInt32(nAS[2], 2)}.{Convert.ToInt32(nAS[3], 2)}");
  245.                         Console.WriteLine();
  246.                         Console.WriteLine("Broadcast Adress: " + BroadcastAdressSubnet);
  247.                         Console.WriteLine($"Broadcast Adress: {Convert.ToInt32(bNS[0], 2)}.{Convert.ToInt32(bNS[1], 2)}.{Convert.ToInt32(bNS[2], 2)}.{Convert.ToInt32(bNS[3], 2)}");
  248.                         Console.WriteLine();
  249.                         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}");
  250.                         Console.WriteLine("========================================================================================================================");
  251.                     }
  252.                 }
  253.                 else if (ip1.StartsWith("0"))
  254.                     {
  255.                         if (inputs[0] == "Subnet")
  256.                         {
  257.                             string binarySubnetNumber = Convert.ToString(int.Parse(inputs[1]), 2);
  258.                             string NetworkAdressSubnet = ip1;
  259.                             for (int a = binarySubnetNumber.Length; a < power; a++)
  260.                             {
  261.                                 NetworkAdressSubnet += "0";
  262.                             }
  263.                             NetworkAdressSubnet += binarySubnetNumber;
  264.                             while (NetworkAdressSubnet.Length < 32)
  265.                             {
  266.                                 NetworkAdressSubnet += "0";
  267.                             }
  268.                             NetworkAdressSubnet = NetworkAdressSubnet.Insert(8, ".");
  269.                             NetworkAdressSubnet = NetworkAdressSubnet.Insert(17, ".");
  270.                             NetworkAdressSubnet = NetworkAdressSubnet.Insert(26, ".");
  271.                             List<string> nAS = NetworkAdressSubnet.Split(".").ToList();
  272.  
  273.  
  274.                             string BroadcastAdressSubnet = ip1;
  275.                             for (int a = binarySubnetNumber.Length; a < power; a++)
  276.                             {
  277.                                 BroadcastAdressSubnet += "0";
  278.                             }
  279.                             BroadcastAdressSubnet += binarySubnetNumber;
  280.                             while (BroadcastAdressSubnet.Length < 32)
  281.                             {
  282.                                 BroadcastAdressSubnet += "1";
  283.                             }
  284.                             BroadcastAdressSubnet = BroadcastAdressSubnet.Insert(8, ".");
  285.                             BroadcastAdressSubnet = BroadcastAdressSubnet.Insert(17, ".");
  286.                             BroadcastAdressSubnet = BroadcastAdressSubnet.Insert(26, ".");
  287.                             List<string> bNS = BroadcastAdressSubnet.Split(".").ToList();
  288.  
  289.                          
  290.                             Console.WriteLine();
  291.                             Console.WriteLine("Network Adress: " + NetworkAdressSubnet);
  292.                             Console.WriteLine($"Network Adress: {Convert.ToInt32(nAS[0], 2)}.{Convert.ToInt32(nAS[1], 2)}.{Convert.ToInt32(nAS[2], 2)}.{Convert.ToInt32(nAS[3], 2)}");
  293.                             Console.WriteLine();
  294.                             Console.WriteLine("Broadcast Adress: " + BroadcastAdressSubnet);
  295.                             Console.WriteLine($"Broadcast Adress: {Convert.ToInt32(bNS[0], 2)}.{Convert.ToInt32(bNS[1], 2)}.{Convert.ToInt32(bNS[2], 2)}.{Convert.ToInt32(bNS[3], 2)}");
  296.                             Console.WriteLine();
  297.                             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}");
  298.                             Console.WriteLine("========================================================================================================================");
  299.                         }
  300.                     }
  301.                     else if (ip1.StartsWith("1"))
  302.                     {
  303.                         if (inputs[0] == "Subnet")
  304.                         {
  305.                             string binarySubnetNumber = Convert.ToString(int.Parse(inputs[1]), 2);
  306.                             string NetworkAdressSubnet = ip1 + "." + ip2;
  307.                             for (int a = binarySubnetNumber.Length; a < power; a++)
  308.                             {
  309.                                 NetworkAdressSubnet += "0";
  310.                             }
  311.                             NetworkAdressSubnet += binarySubnetNumber;
  312.                             while (NetworkAdressSubnet.Length < 33)
  313.                             {
  314.                                 NetworkAdressSubnet += "0";
  315.                             }
  316.                             NetworkAdressSubnet = NetworkAdressSubnet.Insert(17, ".");
  317.                             NetworkAdressSubnet = NetworkAdressSubnet.Insert(26, ".");
  318.                             List<string> nAS = NetworkAdressSubnet.Split(".").ToList();
  319.  
  320.  
  321.                             string BroadcastAdressSubnet = ip1 + "." + ip2;
  322.                             for (int a = binarySubnetNumber.Length; a < power; a++)
  323.                             {
  324.                                 BroadcastAdressSubnet += "0";
  325.                             }
  326.                             BroadcastAdressSubnet += binarySubnetNumber;
  327.                             while (BroadcastAdressSubnet.Length < 33)
  328.                             {
  329.                                 BroadcastAdressSubnet += "1";
  330.                             }
  331.                             BroadcastAdressSubnet = BroadcastAdressSubnet.Insert(17, ".");
  332.                             BroadcastAdressSubnet = BroadcastAdressSubnet.Insert(26, ".");
  333.                             List<string> bNS = BroadcastAdressSubnet.Split(".").ToList();
  334.  
  335.                          
  336.                             Console.WriteLine();
  337.                             Console.WriteLine("Network Adress: " + NetworkAdressSubnet);
  338.                             Console.WriteLine($"Network Adress: {Convert.ToInt32(nAS[0], 2)}.{Convert.ToInt32(nAS[1], 2)}.{Convert.ToInt32(nAS[2], 2)}.{Convert.ToInt32(nAS[3], 2)}");
  339.                             Console.WriteLine();
  340.                             Console.WriteLine("Broadcast Adress: " + BroadcastAdressSubnet);
  341.                             Console.WriteLine($"Broadcast Adress: {Convert.ToInt32(bNS[0], 2)}.{Convert.ToInt32(bNS[1], 2)}.{Convert.ToInt32(bNS[2], 2)}.{Convert.ToInt32(bNS[3], 2)}");
  342.                             Console.WriteLine();
  343.                             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}");
  344.                             Console.WriteLine("========================================================================================================================");
  345.                         }
  346.                     }
  347.                 }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement