private void cmdCheckPorts_Click(object sender, EventArgs e) { DialogResult understood = MessageBox.Show("Before you proceed, you must keep in mind that in order to determine if" + " a port is truly open, you need to have a service listening to that port.\n\n" + "If no service is running behind the port, then the checker will report it as " + "closed no matter if it was forwarded correctly or not.\n\nClick \"Yes\" if you understand this to proceed.", "Information!", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (understood == DialogResult.No) { return; } foreach (ListViewItem item in listPorts.Items) { PortMapping mapping = (PortMapping)item.Tag; if (_portChecker.CheckPort(mapping.Protocol, _publicIp, mapping.Port)) { item.Text = mapping.ToString() + " - Open"; } else { item.Text = mapping.ToString() + " - Closed"; } } }
private void cmdAdd_Click(object sender, System.EventArgs e) { PortMapping mapping = FrmAddPort.GetPortMapping(this); if (mapping == null) { return; } foreach (ListViewItem existingItem in listPorts.Items) { PortMapping addedMapping = (PortMapping)existingItem.Tag; if (!addedMapping.Equals(mapping)) { continue; } MessageBox.Show($"Port number {mapping.Port} is already added to the list.", "Port exists!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } ListViewItem item = new ListViewItem(mapping.ToString()) { Tag = mapping }; listPorts.Items.Add(item); }