private void button4_Click(object sender, EventArgs e) { for (int i = 0; i < listView4.SelectedItems.Count; i++) { if (listView4.SelectedItems[i].Selected) { try { try { NATUPNPLib.UPnPNAT UPnP = new NATUPNPLib.UPnPNAT(); NATUPNPLib.IStaticPortMappingCollection PortMapping = UPnP.StaticPortMappingCollection; PortMapping.Remove(Convert.ToInt32(listView4.SelectedItems[i].SubItems[0].Text), "TCP"); }catch {} if (_listener.Contains(_listener[i])) { _listener[i].Close(); } else if (_FileListener.Contains(_FileListener[i])) { _FileListener[i].Close(); } listView4.SelectedItems[i].Remove(); }catch {} } } }
public void RemoveUPNPMappings() { Logger.Instance.eventLog.WriteEntry("Removing Exisiting UPNP Mappings", EventLogEntryType.Information); string description = String.Format("iStatServerDotNet-{0}", Preferences.Instance.Value("upnpDescription")); NATUPNPLib.UPnPNAT upnpnat = new NATUPNPLib.UPnPNAT(); NATUPNPLib.IStaticPortMappingCollection mappings = upnpnat.StaticPortMappingCollection; foreach (NATUPNPLib.IStaticPortMapping portMapping in mappings) { if (portMapping.Description.Contains(description)) { mappings.Remove(portMapping.ExternalPort, "TCP"); } } Logger.Instance.eventLog.WriteEntry("Finished Removing UPNP Mappings", EventLogEntryType.Information); }