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 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 void NatUtility_DeviceFound(object sender, DeviceEventArgs e) { lock (devices) { if (!devices.Add(e.Device)) { return; } } lock (ports) { foreach (var port in ports) { Mapping mapping_tcp = new Mapping(Protocol.Tcp, port, port, 7200); Mapping mapping_udp = new Mapping(Protocol.Udp, port, port, 7200); e.Device.BeginCreatePortMap(mapping_tcp, OnPortMapCreated, e.Device); e.Device.BeginCreatePortMap(mapping_udp, OnPortMapCreated, e.Device); } } }
private void DeviceFound(object sender, DeviceEventArgs e) { INatDevice device = e.Device; UIConsole.Log ("Found NAT device. External IP is " + device.GetExternalIP()); _device = device; }
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; } }
protected static void HandleDeviceFound(object sender, DeviceEventArgs args) { foreach (Mapping mapping in args.Device.GetAllMappings ()) { Console.WriteLine ("Deleting: " + mapping.ToString ()); args.Device.DeletePortMap (mapping); } manualResetEvent.Set (); }
void NatUtility_DeviceFound(object sender, DeviceEventArgs e) { try { var device = e.Device; _logger.Debug("NAT device found: {0}", device.LocalAddress.ToString()); CreateRules(device); } catch (Exception) { //_logger.ErrorException("Error creating port forwarding rules", ex); } }
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; }
void NatUtility_DeviceFound(object sender, DeviceEventArgs e) { router = e.Device; }
/// <summary> /// Event that handles a new found device /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void DeviceFound(object sender, DeviceEventArgs args) { //Make it thread-safe AddDeviceDelegate AddDeviceInstance = new AddDeviceDelegate(this.AddDevice); this.Invoke(AddDeviceInstance, new object[] { args.Device }); }
private static void UpnpDeviceFound(object sender, DeviceEventArgs args) { INatDevice device = args.Device; if (upnpDevices.Contains(device)) return; foreach (int port in portsToMap) { InternalMapPort(device, port); portsMapped.Add(port); } upnpDevices.Add(device); }
private static void UpnpDeviceLost(object sender, DeviceEventArgs args) { INatDevice device = args.Device; if (upnpDevices.Contains(device)) { if (upnpDevices.Count == 1) //this is the last device { foreach (int port in portsMapped) portsToMap.Add(port); portsMapped.Clear(); } upnpDevices.Remove(device); } }
private void DeviceFound(object sender, DeviceEventArgs args) { INatDevice device = args.Device; NatDevices.Add(device); if (ShouldMapNatDevices) MapDevice(device); DetectedExternalAddress = device.GetExternalIP().ToString(); OnDetectedExternalAddressChanged(DetectedExternalAddress); }
private void NatUtility_DeviceLost(object sender, DeviceEventArgs e) { lock (devices) { devices.Remove(e.Device); } }
private void DeviceLost (object sender, DeviceEventArgs args) { INatDevice device = args.Device; Console.WriteLine ("Device Lost"); Console.WriteLine ("Type: {0}", device.GetType().Name); }
private void DeviceLost(object sender, DeviceEventArgs args) { INatDevice device = args.Device; TryRemoveDevice(device); }
protected static void HandleDeviceFound(object sender, DeviceEventArgs args) { Console.WriteLine (args.Device.LocalAddress.ToString()); manualResetEvent.Set (); }
protected static void HandleDeviceFound(object sender, DeviceEventArgs args) { Console.WriteLine (args.Device.GetExternalIP ().ToString()); manualResetEvent.Set (); }
static void NatUtility_DeviceLost(object sender, DeviceEventArgs e) { lock (syncLock) { for (int i = 0; i < deviceList.Count; ++i) { if (deviceList[i].Equals(e.Device)) { deviceList.RemoveAt(i); i -= 1; } } BoltLog.Info("Lost NAT device at {0}", e.Device.LocalAddress); } }
static void NatUtility_DeviceFound(object sender, DeviceEventArgs e) { lock (syncLock) { foreach (var device in deviceList) { if (device.Equals(e.Device)) { return; } } NatDeviceState deviceState; deviceState = new NatDeviceState { Nat = e.Device }; deviceState.PortMappings = new Dictionary<int, NatPortMapping>(); deviceList.Add(deviceState); BoltLog.Info("Found {0}", deviceState); NatUtility_FindPublicAddress(deviceState); } }
private void upnp_device_found(object sender, DeviceEventArgs args) { INatDevice dev = args.Device; IPAddress pub_ip = null; try { pub_ip = dev.GetExternalIP(); } catch (Exception) { device = null; public_ip = null; } if (dev!=null && pub_ip!=null) { lock (this) { this.device = dev; this.public_ip = pub_ip; } xbs_messages.addInfoMessage(" @ UPnP device found. external IP: " + pub_ip, xbs_message_sender.UPNP); } else xbs_messages.addInfoMessage(" @ UPnP discovery failed. Could not get public IP", xbs_message_sender.UPNP, xbs_message_type.WARNING); }
private void DeviceLost(object sender, DeviceEventArgs e) { //INatDevice device = e.Device; UIConsole.Log ("Lost NAT device!"); }
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); }
void NatUtility_DeviceLost(object sender, DeviceEventArgs e) { var device = e.Device; _logger.Debug("NAT device lost: {0}", device.LocalAddress.ToString()); }
static void HandleDeviceFound(object sender, DeviceEventArgs e) { DeviceFound?.Invoke(sender, e); }
private void OnDeviceFound(DeviceEventArgs args) { if (DeviceFound != null) DeviceFound(this, args); }
void NatUtility_DeviceFound(object sender, DeviceEventArgs e) { try { e.Device.CreatePortMap(new Mapping(Protocol.Tcp, SettingsManager.IncomingPort, SettingsManager.IncomingPort)); NatUtility.StopDiscovery(); } catch { } }
private void OnDeviceFound(object sender, DeviceEventArgs args) { logger.Info("UPnP Device found"); lock (devices) if (!devices.Contains(args.Device)) { devices.Add(args.Device); GLib.Idle.Add (delegate { if (RouterFound != null) RouterFound (this, EventArgs.Empty); return false; }); } MapPort(); }
/// <summary> /// Is called when the connection to a device is lost /// </summary> /// <param name="sender"></param> /// <param name="args"></param> void DeviceLost(object sender, DeviceEventArgs args) { RemoveDeviceDelegate RemoveDeviceInstance = new RemoveDeviceDelegate(RemoveDevice); this.Invoke(RemoveDeviceInstance, new object[] { args.Device }); }
void NatUtility_DeviceFound(object sender, DeviceEventArgs e) { try { var device = e.Device; _logger.Debug("NAT device found: {0}", device.LocalAddress.ToString()); CreateRules(device); } catch (Exception) { // I think it could be a good idea to log the exception because // you are using permanent portmapping here (never expire) and that means that next time // CreatePortMap is invoked it can fails with a 718-ConflictInMappingEntry or not. That depends // on the router's upnp implementation (specs says it should fail however some routers don't do it) // It also can fail with others like 727-ExternalPortOnlySupportsWildcard, 728-NoPortMapsAvailable // and those errors (upnp errors) could be useful for diagnosting. //_logger.ErrorException("Error creating port forwarding rules", ex); } }
private void DeviceFound(object sender, DeviceEventArgs args) { logger.IfInfo("Device Found"); this.Status = NatStatus.DeviceFound; // This is the upnp enabled router this.Device = args.Device; // Create a mapping to forward external port to local port try { Device.CreatePortMap(new Mapping(Protocol.Tcp, Injection.Kernel.Get<IServerSettings>().Port, Injection.Kernel.Get<IServerSettings>().Port)); this.Status = NatStatus.PortForwardedSuccessfully; } catch (Exception e) { this.Status = NatStatus.PortForwardingFailed; logger.Error("Port mapping failed", e); } }