private static void HandleCommandLine(string[] args) { UpnpHelper Upnp; if (args.Length > 0) { if (string.Compare(args[0].ToLower(), "help") == 0) { ShowHelp(); return; } if (string.Compare(args[0].ToLower(), "list") == 0) { Upnp = new UpnpHelper(); Upnp.ListMappings(); return; } if (string.Compare(args[0].ToLower(), "clear") == 0) { Upnp = new UpnpHelper(); Upnp.ClearMappings(); return; } if (string.Compare(args[0].ToLower(), "add") == 0) { HandleAddCommand(args); return; } } ShowUsage(); }
private static void HandleAddCommand(string[] args) { UpnpHelper Upnp; ushort port; string Protocol; if (args.Length != 4) { Console.WriteLine("Invalid number of arguments"); ShowAddUsage(); return; } // Get and check port number try { port = ushort.Parse(args[1]); } catch (Exception e) { Console.WriteLine(e.Message); ShowAddUsage(); return; } if (port < 1) { Console.WriteLine("Port number out of range"); } // Get and check protocol Protocol = args[2].ToUpper(); if (!( (string.Compare(Protocol, "UDP") == 0) ^ (string.Compare(Protocol, "TCP") == 0) )) { Console.WriteLine("Invalid protocol. Must be TCP or UDP"); return; } // Get Description string Description = args[3]; Console.WriteLine("Adding: Port: {0}, Protocol: {1}, Description: {2}", port, Protocol, Description); Upnp = new UpnpHelper(); Upnp.AddMapping(port, Protocol, Description); }