void OnApplicationQuit() { if (natDevice != null) { try { if (udpMapping != null) { natDevice.DeletePortMap(udpMapping); } if (tcpMapping != null) { natDevice.DeletePortMap(tcpMapping); } tcpMapping = udpMapping = null; Debug.Log("Deleted port mapping"); } catch (Exception ex) { Debug.Log("Failed to delete port mapping"); } } NatUtility.StopDiscovery(); CloseServer(); natDevice = null; }
private void DeviceFound(object sender, DeviceEventArgs args) { Mapping minecraftTCP = new Mapping(Protocol.Tcp, 25565, 25565); Mapping minecraftUDP = new Mapping(Protocol.Udp, 25565, 25565); minecraftTCP.Description = "MinecraftTCP"; minecraftUDP.Description = "MinecraftUDP"; device = args.Device; try { device.DeletePortMap(minecraftTCP); device.DeletePortMap(minecraftUDP); } catch { } device.CreatePortMap(minecraftTCP); device.CreatePortMap(minecraftUDP); device.CreatePortMap(new Mapping(Protocol.Udp, 2, 2)); // on device found code //cport.Text = "okay"; }
private void DeviceLost(object sender, DeviceEventArgs args) { INatDevice device = args.Device; device.DeletePortMap(new Mapping(Protocol.Udp, MessagePort, MessagePort)); device.DeletePortMap(new Mapping(Protocol.Udp, CallPort, CallPort)); device.DeletePortMap(new Mapping(Protocol.Udp, CallReceivePort, CallReceivePort)); }
private void DeviceLost(object sender, DeviceEventArgs args) { INatDevice device = args.Device; device.DeletePortMap(new Mapping(Protocol.Tcp, Epicoin.getport, Epicoin.getport)); device.DeletePortMap(new Mapping(Protocol.Tcp, Epicoin.mineport, Epicoin.mineport)); device.DeletePortMap(new Mapping(Protocol.Tcp, Epicoin.peerport, Epicoin.peerport)); device.DeletePortMap(new Mapping(Protocol.Tcp, Epicoin.transport, Epicoin.transport)); }
// Open ports if UPNP device found private void DeviceFound(object sender, DeviceEventArgs args) { INatDevice device = args.Device; // Free TCP and UDP slots device.DeletePortMap(new Mapping(Protocol.Tcp, port, port)); device.DeletePortMap(new Mapping(Protocol.Udp, port, port)); // Open the slots device.CreatePortMap(new Mapping(Protocol.Tcp, port, port)); device.CreatePortMap(new Mapping(Protocol.Udp, port, port)); log.Print(level.System, "UPNP device found, mapping port " + port + "."); }
private void DeviceLost(object sender, DeviceEventArgs args) { INatDevice device = args.Device; MessageBox.Show("Nat device lost!"); if (portEnabled.Value == true) { device.DeletePortMap(new Mapping(Protocol.Tcp, Convert.ToInt32(portTxt.Text), Convert.ToInt32(portTxt.Text))); } else { device.DeletePortMap(new Mapping(Protocol.Tcp, 10578, 10578)); } }
private void DeviceFound(object sender, DeviceEventArgs args) { try { INatDevice device = args.Device; //remove existing port maps that exist on the ports we want foreach (Mapping portMap in device.GetAllMappings()) { if (externalPorts.Contains(portMap.PublicPort)) { Console.WriteLine("Deleting " + portMap.PublicPort.ToString()); device.DeletePortMap(portMap); } } //add the ports we want for our IP for (int i = 0; i <= 2; i++) { Console.WriteLine("Creating IP: " + device.LocalAddress.ToString() + " port: " + i.ToString()); device.CreatePortMap(new Mapping(Protocol.Tcp, internalPorts[i], externalPorts[i])); } } catch (Exception e) { } }
/* * Deletes all port maps. */ public static void DelPortMap() { try { device.DeletePortMap(new Mapping(Protocol.Tcp, PORT, PORT)); } catch (MappingException ex) { AlexaComp._log.Debug(ex.ToString()); } }
public void DeletePortMap(Protocol protocol, int number) { if (!EnabledUpnp || natDevice == null) { return; } natDevice.DeletePortMap(new Mapping(protocol, number, number)); }
private void DeviceFound(object sender, DeviceEventArgs args) { try { INatDevice device = args.Device; Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Device found"); Console.ResetColor(); Console.WriteLine("Type: {0}", device.GetType().Name); Console.WriteLine("Service Type: {0}", (device as UpnpNatDevice).ServiceType); Console.WriteLine("IP: {0}", device.GetExternalIP()); device.CreatePortMap(new Mapping(Protocol.Tcp, 15001, 15001)); Console.WriteLine("---"); //return; /******************************************/ /* Advanced test suite. */ /******************************************/ // Try to create a new port map: var mapping = new Mapping(Protocol.Tcp, 6001, 6001); device.CreatePortMap(mapping); Console.WriteLine("Create Mapping: protocol={0}, public={1}, private={2}", mapping.Protocol, mapping.PublicPort, mapping.PrivatePort); // Try to retrieve confirmation on the port map we just created: try { Mapping m = device.GetSpecificMapping(Protocol.Tcp, 6001); Console.WriteLine("Specific Mapping: protocol={0}, public={1}, private={2}", m.Protocol, m.PublicPort, m.PrivatePort); } catch { Console.WriteLine("Couldn't get specific mapping"); } // Try deleting the port we opened before: try { device.DeletePortMap(mapping); Console.WriteLine("Deleting Mapping: protocol={0}, public={1}, private={2}", mapping.Protocol, mapping.PublicPort, mapping.PrivatePort); } catch { Console.WriteLine("Couldn't delete specific mapping"); } // Try retrieving all port maps: foreach (Mapping mp in device.GetAllMappings()) { Console.WriteLine("Existing Mapping: protocol={0}, public={1}, private={2}", mp.Protocol, mp.PublicPort, mp.PrivatePort); } Console.WriteLine("External IP: {0}", device.GetExternalIP()); Console.WriteLine("Done..."); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); } }
private static void DeviceLost(object sender, DeviceEventArgs args) { INatDevice device = args.Device; foreach (var port in UPnP._port) { device.DeletePortMap(new Mapping(Mono.Nat.Protocol.Tcp, port, port)); } }
public void RemoveUPNP() { try { device.DeletePortMap(mapping); Console.WriteLine("Succesfully removed UPNP entry"); } catch (Exception) {} }
private void UnmapDevice(INatDevice device) { try { device.DeletePortMap(new Mapping(Protocol.Udp, Port, Port)); Relay.Instance.MessageLog.AddMessage("Deleted port mapping."); } catch (MappingException) { Relay.Instance.MessageLog.AddMessage("Unable to delete port mapping. That's odd."); } }
private void DeviceFound(object sender, DeviceEventArgs args) { try { INatDevice device = args.Device; fLogger.WriteInfo("Device found, type: {0}", device.GetType().Name); if (device.GetType().Name == "PmpNatDevice") { fLogger.WriteInfo("Device skipped"); return; } fLogger.WriteInfo("External IP: {0}", device.GetExternalIP()); try { Mapping m; /*Mapping m = device.GetSpecificMapping(Mono.Nat.Protocol.Tcp, ProtocolHelper.PublicTCPPort); * if (m != null) { * fLogger.WriteInfo("Specific Mapping: protocol={0}, public={1}, private={2}", m.Protocol, m.PublicPort, m.PrivatePort); * } else {*/ /*m = new Mapping(Protocol.Tcp, ProtocolHelper.PublicTCPPort, ProtocolHelper.PublicTCPPort); * device.CreatePortMap(m); * fLogger.WriteInfo("Create Mapping: protocol={0}, public={1}, private={2}", m.Protocol, m.PublicPort, m.PrivatePort);*/ //} m = device.GetSpecificMapping(Protocol.Udp, DHTClient.PublicDHTPort); if (m != null) { try { device.DeletePortMap(m); } catch { } } m = new Mapping(Protocol.Udp, DHTClient.PublicDHTPort, DHTClient.PublicDHTPort); device.CreatePortMap(m); fLogger.WriteInfo("Create Mapping: protocol={0}, public={1}, private={2}", m.Protocol, m.PublicPort, m.PrivatePort); } catch (Exception ex) { fLogger.WriteError("Couldn't create specific mapping", ex); } foreach (Mapping mp in device.GetAllMappings()) { fLogger.WriteInfo("Existing Mapping: protocol={0}, public={1}, private={2}", mp.Protocol, mp.PublicPort, mp.PrivatePort); } fUPnPSem.Release(); } catch (Exception ex) { fLogger.WriteError("NATMapper.DeviceFound()", ex); } }
private static void RemovePortMapping(INatDevice device, Mapping m) { Console.WriteLine("Suppression du port " + m.ToString()); var routerMapping = GetMappingFromDevice(device, m); if (routerMapping == null) { Console.WriteLine("Le port " + m.ToString() + " n'existe pas"); } else { device.DeletePortMap(routerMapping); } }
public static void RemovePortforward() { try { var mapping = new Mapping(Protocol.Tcp, Game.Settings.Server.ExternalPort, Game.Settings.Server.ListenPort); NatDevice.DeletePortMap(mapping); Log.Write("server", "Remove port mapping: protocol={0}, public={1}, private={2}", mapping.Protocol, mapping.PublicPort, mapping.PrivatePort); } catch (Exception e) { Log.Write("server", "Can not remove UPnP portforwarding rules: {0}", e); Game.Settings.Server.AllowPortForward = false; } }
void OnApplicationQuit() { if (IsServer) { CloseServer(); } if (IsClient) { Network.Disconnect(); } if (IsRegistered) { MasterServer.UnregisterHost(); } if (natDevice != null) { try { if (udpMapping != null) { natDevice.DeletePortMap(udpMapping); } if (tcpMapping != null) { natDevice.DeletePortMap(tcpMapping); } tcpMapping = udpMapping = null; Debug.Log("Deleted port mapping"); } catch (Exception ex) { Debug.Log("Failed to delete port mapping"); } } NatUtility.StopDiscovery(); }
public void Stop() { if (device == null) { return; } logger.Info("UPnP shutting down"); try{ device.DeletePortMap(map); logger.Info("UPnP port map removal successful(" + map.Protocol + "/" + map.Port + ")"); } catch (MappingException e) { logger.Error("UPnP failed to remove map(" + map.Protocol + "/" + map.Port + ")" + "Error: " + e.ErrorCode + " " + e.ErrorText); } }
private void btRemoveAll_Click(object sender, EventArgs e) { if (lvDevices.SelectedItems.Count > 0) { if (MessageBox.Show("Are you sure you want to remove all mappings?", "Warning!", MessageBoxButtons.YesNo) == DialogResult.Yes) { INatDevice device = GetDeviceByUUID(lvDevices.SelectedItems[0].SubItems[3].Text); foreach (Mapping mp in device.GetAllMappings()) { device.DeletePortMap(mp); } UpdateMappings(lvDevices.SelectedItems[0].SubItems[3].Text); } } }
public static void StopUPnP(INatDevice device, Protocol protocol, int port) { if (GlobalVars.UserConfiguration.UPnP) { Mapping checker = device.GetSpecificMapping(protocol, port); int mapPublic = checker.PublicPort; int mapPrivate = checker.PrivatePort; if (mapPublic != -1 && mapPrivate != -1) { Mapping portmap = new Mapping(protocol, port, port); portmap.Description = "Novetus"; device.DeletePortMap(portmap); } } }
//ellenőrzés public async void upnp_ell(Vezerlofo vzf) { write_file("MCSC: Portok létrehozásának eredményének ellenőrzése", vzf); try { device.DeletePortMap(new Mapping(Protocol.Udp, 2, 2)); write_file("MCSC: Portok sikeresen létrehozva", vzf); } catch { write_file("MCSC-ERROR: PORTOK LÉTREHOZÁSA LEHETETLEN", vzf); MessageBox.Show("Sajnos neked nem elérhető az automatikus port létrehozás"); NatUtility.StopDiscovery(); err = true; } }
private void removeToolStripMenuItem_Click(object sender, EventArgs e) { foreach (ListViewItem i in lstPorts.SelectedItems) { INatDevice device = (INatDevice)i.Tag; int inPort, exPort, protocol; inPort = int.Parse(i.Text); exPort = int.Parse(i.SubItems[1].Text); protocol = (i.SubItems[2].Text == "Tcp" ? 0 : 1); Protocol p = (protocol == 0) ? Protocol.Tcp : Protocol.Udp; device.DeletePortMap(new Mapping(p, inPort, exPort)); } if (lstPorts.SelectedItems.Count > 0) { refresh(); } }
void DeviceFound(object sender, DeviceEventArgs args) { // This is the upnp enabled router INatDevice device = args.Device; // Create a mapping to forward external port 3000 to local port 1500 device.CreatePortMap(new Mapping(Protocol.Tcp, 1500, 3000)); // Retrieve the details for the port map for external port 3000 Mapping m = device.GetSpecificMapping(Protocol.Tcp, 3000); // Get all the port mappings on the device and delete them foreach (Mapping mp in device.GetAllMappings()) { device.DeletePortMap(mp); } // Get the external IP address IPAddress externalIP = device.GetExternalIP(); }
private void DeviceFound(object sender, DeviceEventArgs args) { try { INatDevice device = args.Device; Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Device found"); Console.ResetColor(); Console.WriteLine("Type: {0}", device.GetType().Name); Console.WriteLine("IP: {0}", device.GetExternalIP()); device.CreatePortMap(new Mapping(Protocol.Tcp, 1500, 1500)); Console.WriteLine("---"); return; Mapping mapping = new Mapping(Protocol.Tcp, 6001, 6001); device.CreatePortMap(mapping); Console.WriteLine("Create Mapping: protocol={0}, public={1}, private={2}", mapping.Protocol, mapping.PublicPort, mapping.PrivatePort); try { Mapping m = device.GetSpecificMapping(Protocol.Tcp, 6001); Console.WriteLine("Specific Mapping: protocol={0}, public={1}, private={2}", m.Protocol, m.PublicPort, m.PrivatePort); } catch { Console.WriteLine("Couldnt get specific mapping"); } foreach (Mapping mp in device.GetAllMappings()) { Console.WriteLine("Existing Mapping: protocol={0}, public={1}, private={2}", mp.Protocol, mp.PublicPort, mp.PrivatePort); device.DeletePortMap(mp); } Console.WriteLine("External IP: {0}", device.GetExternalIP()); Console.WriteLine("Done..."); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); } }
public static bool TryRemovePortForward() { if (natDevice == null) { return(false); } try { natDevice.DeletePortMap(mapping); } catch (Exception e) { Console.WriteLine("Port removal failed: {0}", e.Message); Log.Write("nat", e.StackTrace); return(false); } return(true); }
/// <summary> /// Stops the driver by unhooking any event handlers and releasing any used resources. /// </summary> public override void StopDriver() { Logger.DebugFormat("{0} is stopping", DeviceDisplayNameInternal); if (_httpListener != null) { _httpListener.Close(); } if (_enableUpnp) { NatUtility.StopDiscovery(); } if (_uPnpRouter != null) { Logger.InfoFormat("{0} is removing UPnP forwarding for port {1}", DeviceDisplayNameInternal, _portNumber); _uPnpRouter.DeletePortMap(new Mapping(Protocol.Tcp, _portNumber, _portNumber)); } }
public void Unmap(Protocol protocol, int port) { if (router == null) { Start(); Thread.Sleep(5000); } if (router == null) { return; } foreach (Mapping mapping in router.GetAllMappings()) { if (mapping.PublicPort == port && mapping.Protocol == protocol) { router.DeletePortMap(mapping); } } }
private void btRemove_Click(object sender, EventArgs e) { if (lvDevices.SelectedItems.Count > 0) { INatDevice device = GetDeviceByUUID(lvDevices.SelectedItems[0].SubItems[3].Text); for (int i = 0; i < lvMappings.SelectedItems.Count; i++) { foreach (Mapping mp in device.GetAllMappings()) { if (mp.PrivatePort == Convert.ToInt32(lvMappings.SelectedItems[i].SubItems[1].Text) && mp.PublicPort == Convert.ToInt32(lvMappings.SelectedItems[i].SubItems[2].Text) && mp.Protocol.ToString() == lvMappings.SelectedItems[i].SubItems[3].Text && mp.Description == lvMappings.SelectedItems[i].SubItems[0].Text) { device.DeletePortMap(mp); } } } UpdateMappings(lvDevices.SelectedItems[0].SubItems[3].Text); } }
public static void DeletePortMap(int port) { if (!_discoveryComplete) { return; } Mapping mapping; if (_mappings.TryGetValue(port, out mapping)) { try { for (int i = 0; i < 3; i++) { _device.DeletePortMap(mapping); } } catch (MappingException) { } } }
public void upnp_deleteAllPortMappings() { if (isUPnPavailable()) { List <Mapping> mappings; lock (this) { mappings = this.my_PortMappings; this.my_PortMappings = new List <Mapping>(); } try { foreach (Mapping pm in mappings) { device.DeletePortMap(pm); xbs_messages.addInfoMessage(" @ UPnP port mapping removed " + public_ip + ":" + pm.PublicPort, xbs_message_sender.UPNP); } } catch (Exception) { } } }
private static void InternalUnMapPort(INatDevice device, int port) { for (int i = 0; i < 2; i++) { var proto = Protocol.Tcp; if (i > 0) proto = Protocol.Udp; Mapping mapping = device.GetSpecificMapping(proto, port); if (mapping != null && mapping.PrivatePort > 0 && mapping.PublicPort > 0) device.DeletePortMap(new Mapping(proto, port, port)); } }