public static int PortNumberInput(int PreSelected = 1024)
        {
            PortSelect PortSelect = new PortSelect();

            PortSelect.numPort.Value = PreSelected;

            PortSelect.ShowDialog();

            return(PortSelect.PortNum);
        }
        private ToolStripMenuItem CreateHostMenuItem(string Name, RemoteMachine x)
        {
            ToolStripMenuItem HostMenuItem = new ToolStripMenuItem();

            HostMenuItem.Text = x.host;

            HostMenuItem.Name = Name;

            if (x.pending)
            {
                HostMenuItem.Image = Properties.Resources.bullet_blue;
            }
            else if (x.wanip == "")
            {
                HostMenuItem.Image       = Properties.Resources.bullet_red;
                HostMenuItem.ToolTipText = "Host error: could not configure router";
            }
            else if (x.rdpopen == false)
            {
                HostMenuItem.Image       = Properties.Resources.bullet_yellow;
                HostMenuItem.ToolTipText = "Host error: RDP service not listening on this host";
            }
            else if (x.status == "open")
            {
                HostMenuItem.Image = Properties.Resources.bullet_green;
            }
            else
            {
                HostMenuItem.Image = Properties.Resources.bullet_grey;
            }

            HostMenuItem.Tag = x.host;

            if (x.status == "closed")
            {
                ToolStripMenuItem OpenPortMenuItem = new ToolStripMenuItem();
                OpenPortMenuItem.Text   = "Open Port";
                OpenPortMenuItem.Tag    = x.host;
                OpenPortMenuItem.Click += new EventHandler(OpenPortMenuItem_Click);
                HostMenuItem.DropDownItems.Add(OpenPortMenuItem);
            }

            if (x.status == "open" && x.rdpopen == true)
            {
                ToolStripMenuItem ConnectClientMenuItem = new ToolStripMenuItem();
                ConnectClientMenuItem.Text   = "Launch RDP";
                ConnectClientMenuItem.Tag    = x.host;
                ConnectClientMenuItem.Click += new EventHandler(ConnectClientMenuItem_Click);
                if (x.host == Dns.GetHostName() || x.wanip == this.ExternalIp)
                {
                    ConnectClientMenuItem.ToolTipText = "Computer can not connect to itself.";
                    ConnectClientMenuItem.Enabled     = false;
                }
                if (x.wanip == "")
                {
                    ConnectClientMenuItem.ToolTipText = "Remote computer could not determine WAN IP address.";
                    ConnectClientMenuItem.Enabled     = false;
                }
                HostMenuItem.DropDownItems.Add(ConnectClientMenuItem);
            }

            if (x.rdpopen == true)
            {
                ToolStripMenuItem LaunchRDPInternalMenuItem = new ToolStripMenuItem();
                LaunchRDPInternalMenuItem.Text = "Launch RDP [internal]";
                // If this machine is the one the user is on disable it...
                if (x.host == Dns.GetHostName() || x.wanip != this.ExternalIp)
                {
                    LaunchRDPInternalMenuItem.ToolTipText = "Computer can not connect to itself.";
                    LaunchRDPInternalMenuItem.Enabled     = false;
                }
                LaunchRDPInternalMenuItem.Tag    = x.host;
                LaunchRDPInternalMenuItem.Click += new EventHandler(ConnectClientInternalMenuItem_Click);
                HostMenuItem.DropDownItems.Add(LaunchRDPInternalMenuItem);
            }

            if (x.status == "open")
            {
                ToolStripMenuItem ClosePortMenuItem = new ToolStripMenuItem();
                ClosePortMenuItem.Text   = "Close Port";
                ClosePortMenuItem.Tag    = x.host;
                ClosePortMenuItem.Click += new EventHandler(ClosePortMenuItem_Click);
                HostMenuItem.DropDownItems.Add(ClosePortMenuItem);
            }

            ToolStripMenuItem HostPortSettingsMenuItem = new ToolStripMenuItem();

            HostPortSettingsMenuItem.Text = "Port Settings";
            HostMenuItem.DropDownItems.Add(HostPortSettingsMenuItem);

            ToolStripMenuItem RandomizePortMenuItem = new ToolStripMenuItem();

            RandomizePortMenuItem.Text   = "Randomize Port";
            RandomizePortMenuItem.Tag    = x.host;
            RandomizePortMenuItem.Click += new EventHandler(RandomizePortMenuItem_Click);
            HostPortSettingsMenuItem.DropDownItems.Add(RandomizePortMenuItem);

            ToolStripMenuItem PortSetManualMenuItem = new ToolStripMenuItem();

            PortSetManualMenuItem.Text   = "Choose Port";
            PortSetManualMenuItem.Tag    = x.host;
            PortSetManualMenuItem.Click += delegate(Object sender1, EventArgs ee)
            {
                PortSelect ps = new PortSelect();

                ps.numPort.Value = x.port;

                ps.ShowDialog();

                PingRequest.SendCommandToTargetAsync(x.host, "port", ps.numPort.Value.ToString());

                timerTickAsync(null, null);
            };
            HostPortSettingsMenuItem.DropDownItems.Add(PortSetManualMenuItem);

            ToolStripMenuItem HostPortLifetimeSelectMenuItem = new ToolStripMenuItem();

            HostPortLifetimeSelectMenuItem.Text = "Lifetime";
            HostPortLifetimeSelectMenuItem.Tag  = x.host;
            HostPortSettingsMenuItem.DropDownItems.Add(HostPortLifetimeSelectMenuItem);

            foreach (KeyValuePair <int, string> Life in this.Lifetimes)
            {
                ToolStripMenuItem i = new ToolStripMenuItem();
                i.Text = Life.Value;
                if (Life.Key == x.lifetime)
                {
                    i.Checked = true;
                }
                i.Click += delegate(Object sender1, EventArgs ee)
                {
                    ToolStripMenuItem s = sender1 as ToolStripMenuItem;

                    PingRequest.SendCommandToTargetAsync(x.host, "lifetime", Life.Key.ToString());

                    timerTickAsync(null, null);
                };
                HostPortLifetimeSelectMenuItem.DropDownItems.Add(i);
            }

            ToolStripMenuItem MachineIntervalMenuItem = new ToolStripMenuItem();

            MachineIntervalMenuItem.Text = "Ping Interval";
            HostMenuItem.DropDownItems.Add(MachineIntervalMenuItem);

            foreach (KeyValuePair <int, string> Ping in this.PingsIntervals)
            {
                ToolStripMenuItem i = new ToolStripMenuItem();
                i.Text = Ping.Value;
                i.Tag  = Ping.Key;
                if (Ping.Key == x.interval)
                {
                    i.Checked = true;
                }
                i.Click += delegate(Object sender1, EventArgs ee)
                {
                    ToolStripMenuItem s = sender1 as ToolStripMenuItem;

                    PingRequest.SendCommandToTargetAsync(x.host, "interval", Ping.Key.ToString());

                    timerTickAsync(null, null);
                };
                MachineIntervalMenuItem.DropDownItems.Add(i);
            }

            ToolStripMenuItem TestCommandMenuItem = new ToolStripMenuItem();

            TestCommandMenuItem.Text   = "Test Command Bus";
            TestCommandMenuItem.Tag    = x.host;
            TestCommandMenuItem.Click += new EventHandler(SendTestCommand);
            HostMenuItem.DropDownItems.Add(TestCommandMenuItem);

            HostMenuItem.DropDownItems.Add("-");

            ToolStripMenuItem MachineStatusMenuItem = new ToolStripMenuItem();

            MachineStatusMenuItem.Text  = "Machine Information";
            MachineStatusMenuItem.Tag   = x.host;
            MachineStatusMenuItem.Width = 400;
            HostMenuItem.DropDownItems.Add(MachineStatusMenuItem);

            int  width = 300;
            Font f     = new Font("Consolas", 9);

            MachineStatusMenuItem.DropDownItems.AddRange(new ToolStripItem[] {
                new ToolStripLabel
                {
                    Text  = "Host Name         :  " + x.host,
                    Width = width,
                    Font  = f
                },
                new ToolStripLabel
                {
                    Text  = "Machine GUID      :  " + x.guid,
                    Width = width,
                    Font  = f
                },
                new ToolStripLabel
                {
                    Text  = "External IP       :  " + x.wanip,
                    Width = width,
                    Font  = f
                },
                new ToolStripLabel
                {
                    Text  = "Internal IP       :  " + x.lanip,
                    Width = width,
                    Font  = f
                },
                new ToolStripLabel
                {
                    Text  = "Mapped Port       :  " + x.port,
                    Width = width,
                    Font  = f
                },
                new ToolStripLabel
                {
                    Text  = "Interval          :  " + x.interval + " Seconds",
                    Width = width,
                    Font  = f
                },
                new ToolStripLabel
                {
                    Text  = "Version           :  " + x.version,
                    Width = width,
                    Font  = f
                },
                new ToolStripLabel
                {
                    Text  = "Port Lifetime     :  " + x.lifetime + " Minutes",
                    Width = width,
                    Font  = f
                },
                new ToolStripLabel
                {
                    Text  = "Port Status       :  " + x.status,
                    Width = width,
                    Font  = f
                },
                new ToolStripLabel
                {
                    Text  = "Service Installed :  " + x.serviceinstalled,
                    Width = width,
                    Font  = f
                },
                new ToolStripLabel
                {
                    Text  = "Service Running   :  " + x.servicerunning,
                    Width = width,
                    Font  = f
                }
            });

            return(HostMenuItem);
        }