Exemplo n.º 1
0
        //const string paramExternalPort = "ext";
        //const string paramProtocol = "proto";
        //const string paramAddress = "ip";
        //const string paramPort = "port";
        //const string paramDisabled = "disabled";
        //const string paramEnabled = "enabled";
        //const string paramDescription = "desc";

        //private static void ParseParameters(string[] args)
        //{
        //    for(int i=1; i<args.Length; i++)
        //    {

        //    }
        //}

        private static void ListMappings(UPnPNAT upnpNAT, string[] args)
        {
            if (args.Length > 1)
            {
                FailureExit(HRESULT.E_INVALIDARG, "Parameters not yet implemented.");
            }

            IStaticPortMappingCollection staticMappings = upnpNAT.StaticPortMappingCollection;

            if (staticMappings == null)
            {
                FailureExit(HRESULT.S_FALSE, "Could not retrieve static port mappings from NAT router. This can happen if it does not support UPnP (or it is not enabled).");
            }

            Console.Write("Found " + staticMappings.Count + " port mappings");
            if (staticMappings.Count > 0)
            {
                Console.WriteLine(":");
                Console.WriteLine();

                PrintPortMappingHeader();

                IEnumerator enumerat0r = staticMappings.GetEnumerator();
                while (enumerat0r.MoveNext())
                {
                    IStaticPortMapping portMapping = enumerat0r.Current as IStaticPortMapping;
                    if (portMapping == null)
                    {
                        FailureExit(HRESULT.E_UNEXPECTED, "The port mappings just got updated or changed otherwise. Please run me again to get the current results.");
                    }

                    PrintPortMapping(portMapping);
                }

                PrintPortMappingFooter();
            }
            else
            {
                Console.WriteLine(".");
            }

            Console.WriteLine();
        }