public Subnetwork(SubnetMask mask, int subnet_index) { this.SubnetMask = mask; this.SubnetIndex = subnet_index; if (subnet_index >= mask.SubnetCount) { throw new ArgumentException("subnet_index too large"); } }
static void Main() { ConsoleColor OutputForeColor = ConsoleColor.Green; ConsoleColor InputForeColor = ConsoleColor.White; ConsoleColor OutputBackColor = ConsoleColor.Black; ConsoleColor InputBackColor = ConsoleColor.Black; string mode = ""; string input = null; string temp = null; while (true) { try { WriteColor(mode + "> ", InputForeColor, InputBackColor); input = Console.ReadLine().Trim(); temp = input.ToUpper().Trim(); string[] args = CommandHandler.GetArgs(input); switch (args[0].ToUpper()) { case "CLEAR": Console.BackgroundColor = ConsoleColor.Black; Console.Clear(); break; case "EXIT": mode = null; break; case "IP": mode = "IP"; break; case "SM": mode = "SM"; break; case "TITLE": Console.Title = args[1]; break; case "WIDTH": int w = Int32.Parse(args[1]); Console.WindowWidth = w; Console.BufferWidth = w; break; case "BEEP": switch (args[1]) { case "?": WriteColor("<37-32767> frequency (Hz)\n", OutputForeColor, OutputBackColor); break; default: int frequency = Int32.Parse(args[1]); switch (args[2]) { case "?": WriteColor("<0-2147483647> duration (ms)\n", OutputForeColor, OutputBackColor); break; default: int duration = Int32.Parse(args[2]); Console.Beep(frequency, duration); break; } break; } break; case "COLOR": switch (args[1].ToUpper()) { case "INPUT": switch (args[2].ToUpper()) { case "FOREGROUND": if (args[3] == "?") { WriteColor(ColorList, OutputForeColor, OutputBackColor); } else { InputForeColor = ParseColor(args[3]); } break; case "BACKGROUND": if (args[3] == "?") { WriteColor(ColorList, OutputForeColor, OutputBackColor); } else { InputBackColor = ParseColor(args[3]); } break; case "?": WriteColor("foreground\nbackground\n", OutputForeColor, OutputBackColor); break; default: WriteColor("Invalid command: '" + args[2] + "'\n", OutputForeColor, OutputBackColor); break; } break; case "OUTPUT": switch (args[2].ToUpper()) { case "FOREGROUND": if (args[3] == "?") { WriteColor(ColorList, OutputForeColor, OutputBackColor); } else { OutputForeColor = ParseColor(args[3]); } break; case "BACKGROUND": if (args[3] == "?") { WriteColor(ColorList, OutputForeColor, OutputBackColor); } else { OutputBackColor = ParseColor(args[3]); } break; case "?": WriteColor("foreground\nbackground\n", OutputForeColor, OutputBackColor); break; default: WriteColor("Invalid command: '" + args[2] + "'\n", OutputForeColor, OutputBackColor); break; } break; case "?": WriteColor("input\noutput\n", OutputForeColor, OutputBackColor); break; default: WriteColor("Invalid command: '" + args[1] + "'\n", OutputForeColor, OutputBackColor); break; } break; case "?": WriteColor("clear\nexit\nip\nsm\ntitle\nwidth\nbeep\ncolor\n", OutputForeColor, OutputBackColor); break; default: switch (mode) { case "IP": IPAddress ipaddr = new IPAddress(args[0]); WriteColor(ipaddr.Info + "\n", OutputForeColor, OutputBackColor); break; case "SM": SubnetMask smaddr = new SubnetMask(args[0]); WriteColor(smaddr.Info + "\n", OutputForeColor, OutputBackColor); break; default: WriteColor("Invalid command: '" + args[0] + "'\n", OutputForeColor, OutputBackColor); break; } break; } } catch { WriteColor("Error\n", OutputForeColor, OutputBackColor); } } }