Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Console.ForegroundColor = ConsoleColor.White;
- string input = Console.ReadLine();
- 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;
- for (int a = 8; a > binary1.Length; a--)
- {
- ip1 += "0";
- }
- ip1 += binary1;
- for (int a = 8; a > binary2.Length; a--)
- {
- ip2 += "0";
- }
- ip2 += binary2;
- for (int a = 8; a > binary3.Length; a--)
- {
- ip3 += "0";
- }
- ip3 += binary3;
- for (int a = 8; a > binary4.Length; a--)
- {
- ip4 += "0";
- }
- ip4 += binary4;
- Console.WriteLine("========================================================================================================================");
- Console.WriteLine($"IP: {ip1}.{ip2}.{ip3}.{ip4}");
- Console.WriteLine("IP: " + input);
- Console.WriteLine();
- if (ip1.StartsWith("110"))
- {
- Console.WriteLine("Network: Class C");
- Console.WriteLine();
- Console.WriteLine($"Subnet Mask: 11111111.11111111.11111111.00000000");
- Console.WriteLine($"Subnet Mask: 255.255.255.0");
- Console.WriteLine();
- Console.WriteLine($"Network Adress: {ip1}.{ip2}.{ip3}.00000000");
- Console.WriteLine($"Network Adress: {inputs[0]}.{inputs[1]}.{inputs[2]}.0");
- Console.WriteLine();
- Console.WriteLine($"Broadcast Adress: {ip1}.{ip2}.{ip3}.11111111");
- Console.WriteLine($"Broadcast Adress: {inputs[0]}.{inputs[1]}.{inputs[2]}.255");
- Console.WriteLine();
- Console.WriteLine($"Range: {inputs[0]}.{inputs[1]}.{inputs[2]}.1 to {inputs[0]}.{inputs[1]}.{inputs[2]}.254");
- }
- else if (ip1.StartsWith("0"))
- {
- Console.WriteLine("Network: Class A");
- Console.WriteLine();
- Console.WriteLine($"Subnet Mask: 11111111.00000000.00000000.00000000");
- Console.WriteLine($"Subnet Mask: 255.0.0.0");
- Console.WriteLine();
- Console.WriteLine($"Network Adress: {ip1}.00000000.00000000.00000000");
- Console.WriteLine($"Network Adress: {inputs[0]}.0.0.0");
- Console.WriteLine();
- Console.WriteLine($"Broadcast Adress: {ip1}.11111111.11111111.11111111");
- Console.WriteLine($"Broadcast Adress: {inputs[0]}.255.255.255");
- Console.WriteLine();
- Console.WriteLine($"Range: {inputs[0]}.0.0.1 to {inputs[0]}.255.255.254");
- }
- else if (ip1.StartsWith("1"))
- {
- Console.WriteLine("Network: Class B");
- Console.WriteLine();
- Console.WriteLine($"Subnet Mask: 11111111.11111111.00000000.00000000");
- Console.WriteLine($"Subnet Mask: 255.255.0.0");
- Console.WriteLine();
- Console.WriteLine($"Network Adress: {ip1}.{ip2}.00000000.00000000");
- Console.WriteLine($"Network Adress: {inputs[0]}.{inputs[1]}.0.0");
- Console.WriteLine();
- Console.WriteLine($"Broadcast Adress: {ip1}.{ip2}.11111111.11111111");
- Console.WriteLine($"Broadcast Adress: {inputs[0]}.{inputs[1]}.255.255");
- Console.WriteLine();
- Console.WriteLine($"Range: {inputs[0]}.{inputs[1]}.0.1 to {inputs[0]}.{inputs[1]}.255.254");
- }
- Console.WriteLine("========================================================================================================================");
- int power = 0;
- input = Console.ReadLine();
- while (true)
- {
- inputs = input.Split(" ").ToList();
- int SubnetCount = int.Parse(inputs[1]);
- if (inputs[0] == "CreateSubnet")
- {
- if (ip1.StartsWith("110") && SubnetCount > 255)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("Cannot create more than 255 subnets with Class C network!");
- Console.ForegroundColor = ConsoleColor.White;
- input = Console.ReadLine();
- }
- else if (ip1.StartsWith("0") && SubnetCount > 16777215)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("Cannot create more than 16 777 215 subnets with Class A network!");
- Console.ForegroundColor = ConsoleColor.White;
- input = Console.ReadLine();
- }
- else if (ip1.StartsWith("1") && SubnetCount > 65535)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("Cannot create more than 65 535 subnets with Class B network!");
- Console.ForegroundColor = ConsoleColor.White;
- input = Console.ReadLine();
- }
- else
- {
- for (int n = 0; n < 25; n++)
- {
- if (SubnetCount <= Math.Pow(2, n))
- {
- power = n;
- break;
- }
- }
- if (ip1.StartsWith("110"))
- {
- string subnetMaskSubnet = "11111111.11111111.11111111";
- for (int q = 0; q < power; q++)
- {
- subnetMaskSubnet += "1";
- }
- while (subnetMaskSubnet.Length < 34)
- {
- subnetMaskSubnet += "0";
- }
- subnetMaskSubnet = subnetMaskSubnet.Insert(26, ".");
- List<string> sMS = subnetMaskSubnet.Split(".").ToList();
- Console.WriteLine();
- Console.WriteLine("Subnet Mask: " + subnetMaskSubnet);
- Console.WriteLine($"Subnet Mask: {Convert.ToInt32(sMS[0], 2)}.{Convert.ToInt32(sMS[1], 2)}.{Convert.ToInt32(sMS[2], 2)}.{Convert.ToInt32(sMS[3], 2)}");
- Console.WriteLine("========================================================================================================================");
- }
- else if (ip1.StartsWith("0"))
- {
- string subnetMaskSubnet = "11111111";
- for (int q = 0; q < power; q++)
- {
- subnetMaskSubnet += "1";
- }
- while (subnetMaskSubnet.Length < 32)
- {
- subnetMaskSubnet += "0";
- }
- subnetMaskSubnet = subnetMaskSubnet.Insert(8, ".");
- subnetMaskSubnet = subnetMaskSubnet.Insert(17, ".");
- subnetMaskSubnet = subnetMaskSubnet.Insert(26, ".");
- List<string> sMS = subnetMaskSubnet.Split(".").ToList();
- Console.WriteLine();
- Console.WriteLine("Subnet Mask: " + subnetMaskSubnet);
- Console.WriteLine($"Subnet Mask: {Convert.ToInt32(sMS[0], 2)}.{Convert.ToInt32(sMS[1], 2)}.{Convert.ToInt32(sMS[2], 2)}.{Convert.ToInt32(sMS[3], 2)}");
- Console.WriteLine("========================================================================================================================");
- }
- else if (ip1.StartsWith("1"))
- {
- string subnetMaskSubnet = "11111111.11111111";
- for (int q = 0; q < power; q++)
- {
- subnetMaskSubnet += "1";
- }
- while (subnetMaskSubnet.Length < 33)
- {
- subnetMaskSubnet += "0";
- }
- subnetMaskSubnet = subnetMaskSubnet.Insert(17, ".");
- subnetMaskSubnet = subnetMaskSubnet.Insert(26, ".");
- List<string> sMS = subnetMaskSubnet.Split(".").ToList();
- Console.WriteLine();
- Console.WriteLine("Subnet Mask: " + subnetMaskSubnet);
- Console.WriteLine($"Subnet Mask: {Convert.ToInt32(sMS[0], 2)}.{Convert.ToInt32(sMS[1], 2)}.{Convert.ToInt32(sMS[2], 2)}.{Convert.ToInt32(sMS[3], 2)}");
- Console.WriteLine("========================================================================================================================");
- }
- break;
- }
- }
- }
- while (true)
- {
- input = Console.ReadLine();
- inputs = input.Split(" ").ToList();
- if (ip1.StartsWith("110"))
- {
- if (inputs[0] == "Subnet")
- {
- string binarySubnetNumber = Convert.ToString(int.Parse(inputs[1]), 2);
- string NetworkAdressSubnet = ip1 + "." + ip2 + "." + ip3;
- for (int a = binarySubnetNumber.Length; a < power; a++)
- {
- NetworkAdressSubnet += "0";
- }
- NetworkAdressSubnet += binarySubnetNumber;
- while (NetworkAdressSubnet.Length < 34)
- {
- NetworkAdressSubnet += "0";
- }
- NetworkAdressSubnet = NetworkAdressSubnet.Insert(26, ".");
- List<string> nAS = NetworkAdressSubnet.Split(".").ToList();
- string BroadcastAdressSubnet = ip1 + "." + ip2 + "." + ip3;
- for (int a = binarySubnetNumber.Length; a < power; a++)
- {
- BroadcastAdressSubnet += "0";
- }
- BroadcastAdressSubnet += binarySubnetNumber;
- while (BroadcastAdressSubnet.Length < 34)
- {
- BroadcastAdressSubnet += "1";
- }
- 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("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("========================================================================================================================");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement