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); } }
public static void DeviceFound(object sender, DeviceEventArgs args) { if (args.Device == null) return; Log.Write("server", "NAT device discovered."); Game.Settings.Server.NatDeviceAvailable = true; Game.Settings.Server.AllowPortForward = true; try { NatDevice = args.Device; Log.Write("server", "Type: {0}", NatDevice.GetType()); Log.Write("server", "Your external IP is: {0}", NatDevice.GetExternalIP()); foreach (var mp in NatDevice.GetAllMappings()) Log.Write("server", "Existing port mapping: protocol={0}, public={1}, private={2}", mp.Protocol, mp.PublicPort, mp.PrivatePort); } catch (Exception e) { Log.Write("server", "Can't fetch information from NAT device: {0}", e); Game.Settings.Server.NatDeviceAvailable = false; Game.Settings.Server.AllowPortForward = false; } }
public static void DeviceFound(object sender, DeviceEventArgs args) { if (args.Device == null) { return; } Log.Write("server", "NAT device discovered."); Game.Settings.Server.NatDeviceAvailable = true; Game.Settings.Server.AllowPortForward = true; try { NatDevice = args.Device; Log.Write("server", "Type: {0}", NatDevice.GetType()); Log.Write("server", "Your external IP is: {0}", NatDevice.GetExternalIP()); foreach (var mp in NatDevice.GetAllMappings()) { Log.Write("server", "Existing port mapping: protocol={0}, public={1}, private={2}", mp.Protocol, mp.PublicPort, mp.PrivatePort); } } catch (Exception e) { Log.Write("server", "Can't fetch information from NAT device: {0}", e); Game.Settings.Server.NatDeviceAvailable = false; Game.Settings.Server.AllowPortForward = false; } }
private void DeviceLost(object sender, DeviceEventArgs args) { INatDevice device = args.Device; Console.WriteLine("Device Lost"); Console.WriteLine("Type: {0}", device.GetType().Name); }
public void DeviceLost(object sender, DeviceEventArgs args) { INatDevice device = args.Device; logger.Fatal("Device Lost"); logger.Fatal("Type: {0}", device.GetType().Name); }
private void DeviceFound(object sender, DeviceEventArgs args) { try { INatDevice device = args.Device; logger.Fatal("UPNP Enabled Device found"); logger.Info("Type: {0}", device.GetType().Name); logger.Info("External IP: {0}", device.GetExternalIP()); Mapping mapping = new Mapping(Protocol.Udp, Convert.ToInt32(uxServerPortUdp.Text), Convert.ToInt32(uxServerPortUdp.Text)); device.CreatePortMap(mapping); logger.Info("Create Mapping: protocol={0}, public={1}, private={2}", mapping.Protocol, mapping.PublicPort, mapping.PrivatePort); try { Mapping m = device.GetSpecificMapping(Protocol.Udp, Convert.ToInt32(uxServerPortUdp.Text)); logger.Info("Testing port Mapping passed: protocol={0}, public={1}, private={2}", m.Protocol, m.PublicPort, m.PrivatePort); // Se il portfoward funziona interrompiamo il discovery // NOTA: rileviamo solo il primo router della lista NatUtility.StopDiscovery(); } catch { logger.Fatal("Could not get specific mapping"); } } catch (Exception ex) { logger.Fatal(ex.Message); logger.Fatal(ex.StackTrace); } }
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 void DeviceLost(object sender, DeviceEventArgs args) { this.Status = NatStatus.PortForwardingFailed; INatDevice device = args.Device; logger.IfInfo("Device Lost"); logger.IfInfo("Type: " + device.GetType().Name); }
public static void StoppingNatDiscovery() { Log.Write("server", "Stopping NAT discovery."); NatUtility.StopDiscovery(); if (NatDevice == null || NatDevice.GetType() != typeof(Mono.Nat.Upnp.UpnpNatDevice)) { Log.Write("server", "No NAT devices with UPnP enabled found within {0} ms deadline. Disabling automatic port forwarding.".F(Game.Settings.Server.NatDiscoveryTimeout)); Game.Settings.Server.NatDeviceAvailable = false; Game.Settings.Server.AllowPortForward = false; } }
private static void DeviceFound(object sender, DeviceEventArgs args) { try { INatDevice device = args.Device; fLogger.WriteInfo("Device found"); fLogger.WriteInfo("Type: {0}", device.GetType().Name); fLogger.WriteInfo("External IP: {0}", device.GetExternalIP()); try { 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(Mono.Nat.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(Mono.Nat.Protocol.Udp, DHTClient.PublicDHTPort); if (m != null) { fLogger.WriteInfo("Specific Mapping: protocol={0}, public={1}, private={2}", m.Protocol, m.PublicPort, m.PrivatePort); } else { m = new Mapping(Mono.Nat.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 { fLogger.WriteInfo("Couldnt get specific mapping"); } foreach (Mapping mp in device.GetAllMappings()) { fLogger.WriteInfo("Existing Mapping: protocol={0}, public={1}, private={2}", mp.Protocol, mp.PublicPort, mp.PrivatePort); } fLogger.WriteInfo("Done..."); } catch (Exception ex) { fLogger.WriteError("NATMapper.DeviceFound()", ex); } }
private async 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}", await device.GetExternalIPAsync()); await device.CreatePortMapAsync(new Mapping(Protocol.Tcp, 1500, 1500)); Console.WriteLine("---"); return; Mapping mapping = new Mapping(Protocol.Tcp, 6001, 6001); await device.CreatePortMapAsync(mapping); Console.WriteLine("Create Mapping: protocol={0}, public={1}, private={2}", mapping.Protocol, mapping.PublicPort, mapping.PrivatePort); try { Mapping m = await device.GetSpecificMappingAsync(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 await device.GetAllMappingsAsync()) { Console.WriteLine("Existing Mapping: protocol={0}, public={1}, private={2}", mp.Protocol, mp.PublicPort, mp.PrivatePort); await device.DeletePortMapAsync(mp); } Console.WriteLine("External IP: {0}", await device.GetExternalIPAsync()); Console.WriteLine("Done..."); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); } }
public static void DeviceLost(object sender, DeviceEventArgs args) { Log.Write("server", "NAT device lost."); if (args.Device == null) return; try { NatDevice = args.Device; Log.Write("server", "Type: {0}", NatDevice.GetType()); } catch (Exception e) { Log.Write("server", "Can't fetch type from lost NAT device: {0}", e); } Game.Settings.Server.NatDeviceAvailable = false; Game.Settings.Server.AllowPortForward = false; }
public static void DeviceLost(object sender, DeviceEventArgs args) { Log.Write("server", "NAT device lost."); if (args.Device == null) { return; } try { NatDevice = args.Device; Log.Write("server", "Type: {0}", NatDevice.GetType()); } catch (Exception e) { Log.Write("server", "Can't fetch type from lost NAT device: {0}", e); } Game.Settings.Server.NatDeviceAvailable = false; Game.Settings.Server.AllowPortForward = false; }
public void DeviceFound(object sender, DeviceEventArgs args) { try { INatDevice device = args.Device; logger.Info("Trovato dispositivo con UPNP abilitato."); logger.Info("Tipo: {0}", device.GetType().Name); logger.Info("IP Esterno del dispositivo: {0}", device.GetExternalIP()); Mapping mapTcp = new Mapping(Protocol.Tcp, Convert.ToInt32(tcpport), Convert.ToInt32(tcpport)); logger.Info("Creazione del PortMapping sul dispositivo UPNP: Protocollo={0}, Porta Public={1}, private={2}", mapTcp.Protocol, mapTcp.PublicPort, mapTcp.PrivatePort); device.CreatePortMap(mapTcp); Mapping mapUdp = new Mapping(Protocol.Udp, Convert.ToInt32(udpport), Convert.ToInt32(udpport)); logger.Info("Creazione del PortMapping sul dispositivo UPNP: Protocollo={0}, Porta Public={1}, private={2}", mapUdp.Protocol, mapUdp.PublicPort, mapUdp.PrivatePort); device.CreatePortMap(mapUdp); Mapping mapTcp2 = device.GetSpecificMapping(Protocol.Tcp, Convert.ToInt32(tcpport)); PortMappingOkTcp = true; logger.Info("Verifica del PortMapping Protocollo={0}, Porta={1} passata con successo", mapTcp2.Protocol, mapTcp2.PublicPort); Mapping mapUdp2 = device.GetSpecificMapping(Protocol.Udp, Convert.ToInt32(udpport)); PortMappingOkUdp = true; logger.Info("Verifica del PortMapping Protocollo={0}, Porta={1} passata con successo", mapUdp2.Protocol, mapUdp2.PublicPort); // Se il portfoward funziona interrompiamo il discovery // NOTA: rileviamo solo il primo router della lista NatUtility.StopDiscovery(); } catch (Exception ex) { logger.Fatal("Procedura UPNP Fallita."); logger.Fatal(ex.Message); logger.Fatal(ex.StackTrace); } }
private async void DeviceFound(object sender, DeviceEventArgs args) { await locker.WaitAsync(); try { INatDevice device = args.Device; // Only interact with one device at a time. Some devices support both // upnp and nat-pmp. Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Device found: {0}", device.NatProtocol); Console.ResetColor(); Console.WriteLine("Type: {0}", device.GetType().Name); Console.WriteLine("IP: {0}", await device.GetExternalIPAsync()); Console.WriteLine("---"); //return; /******************************************/ /* Advanced test suite. */ /******************************************/ // Try to create a new port map: var mapping = new Mapping(Protocol.Tcp, 6001, 6011); await device.CreatePortMapAsync(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 = await device.GetSpecificMappingAsync(Protocol.Tcp, mapping.PublicPort); 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 retrieving all port maps: try { var mappings = await device.GetAllMappingsAsync(); if (mappings.Length == 0) { Console.WriteLine("No existing uPnP mappings found."); } foreach (Mapping mp in mappings) { Console.WriteLine("Existing Mappings: protocol={0}, public={1}, private={2}", mp.Protocol, mp.PublicPort, mp.PrivatePort); } } catch { Console.WriteLine("Couldn't get all mappings"); } // Try deleting the port we opened before: try { await device.DeletePortMapAsync(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: try { var mappings = await device.GetAllMappingsAsync(); if (mappings.Length == 0) { Console.WriteLine("No existing uPnP mappings found."); } foreach (Mapping mp in mappings) { Console.WriteLine("Existing Mapping: protocol={0}, public={1}, private={2}", mp.Protocol, mp.PublicPort, mp.PrivatePort); } } catch { Console.WriteLine("Couldn't get all mappings"); } Console.WriteLine("External IP: {0}", await device.GetExternalIPAsync()); Console.WriteLine("Done..."); } finally { locker.Release(); } }