コード例 #1
1
ファイル: Main.cs プロジェクト: heshamnet16/Mono.Nat
		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);
			}
		}
コード例 #2
1
ファイル: frmMain.cs プロジェクト: ChristianSacramento/ariete
        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);
            }
        }
コード例 #3
1
 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);
         }
     }
 }
コード例 #4
0
ファイル: PortMapper.cs プロジェクト: alextalvan/Ships2
    private void DeviceFound(object sender, DeviceEventArgs e)
    {
        INatDevice device = e.Device;

        UIConsole.Log ("Found NAT device. External IP is " + device.GetExternalIP());
        _device = device;
    }
コード例 #5
0
ファイル: UPnP.cs プロジェクト: Generalcamo/OpenRA
        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;
            }
        }
コード例 #6
0
ファイル: clearpf.cs プロジェクト: asjadsyed/pftools
 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 ();
 }
コード例 #7
0
        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);
            }
        }
コード例 #8
0
ファイル: UPnP.cs プロジェクト: Generalcamo/OpenRA
        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;
        }
コード例 #9
0
 void NatUtility_DeviceFound(object sender, DeviceEventArgs e)
 {
     router = e.Device;
 }
コード例 #10
0
 /// <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 });
 }
コード例 #11
0
        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);
        }
コード例 #12
0
        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);
            }
        }
コード例 #13
0
ファイル: Relay.cs プロジェクト: merveilles/WaitingForHorus
    private void DeviceFound(object sender, DeviceEventArgs args)
    {
        INatDevice device = args.Device;

        NatDevices.Add(device);
        if (ShouldMapNatDevices)
            MapDevice(device);

        DetectedExternalAddress = device.GetExternalIP().ToString();
        OnDetectedExternalAddressChanged(DetectedExternalAddress);
    }
コード例 #14
0
 private void NatUtility_DeviceLost(object sender, DeviceEventArgs e)
 {
     lock (devices) {
         devices.Remove(e.Device);
     }
 }
コード例 #15
0
ファイル: Main.cs プロジェクト: heshamnet16/Mono.Nat
		private void DeviceLost (object sender, DeviceEventArgs args)
		{
			INatDevice device = args.Device;
			
			Console.WriteLine ("Device Lost");
			Console.WriteLine ("Type: {0}", device.GetType().Name);
		}
コード例 #16
0
ファイル: Relay.cs プロジェクト: merveilles/WaitingForHorus
    private void DeviceLost(object sender, DeviceEventArgs args)
    {
        INatDevice device = args.Device;

        TryRemoveDevice(device);
    }
コード例 #17
0
ファイル: getinip.cs プロジェクト: asjadsyed/pftools
 protected static void HandleDeviceFound(object sender, DeviceEventArgs args)
 {
     Console.WriteLine (args.Device.LocalAddress.ToString());
     manualResetEvent.Set ();
 }
コード例 #18
0
ファイル: getexip.cs プロジェクト: asjadsyed/pftools
 protected static void HandleDeviceFound(object sender, DeviceEventArgs args)
 {
     Console.WriteLine (args.Device.GetExternalIP ().ToString());
     manualResetEvent.Set ();
 }
コード例 #19
0
ファイル: BoltUPnP.cs プロジェクト: PeWiNi/gamedev15
        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);
              }
        }
コード例 #20
0
ファイル: BoltUPnP.cs プロジェクト: PeWiNi/gamedev15
        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);
              }
        }
コード例 #21
0
ファイル: xbs_natstun.cs プロジェクト: Ch0wW/XBSlink
 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);
 }
コード例 #22
0
ファイル: PortMapper.cs プロジェクト: alextalvan/Ships2
 private void DeviceLost(object sender, DeviceEventArgs e)
 {
     //INatDevice device = e.Device;
     UIConsole.Log ("Lost NAT device!");
 }
コード例 #23
0
ファイル: NatService.cs プロジェクト: einsteinx2/WaveBox
        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);
        }
コード例 #24
0
 void NatUtility_DeviceLost(object sender, DeviceEventArgs e)
 {
     var device = e.Device;
     _logger.Debug("NAT device lost: {0}", device.LocalAddress.ToString());
 }
コード例 #25
0
 static void HandleDeviceFound(object sender, DeviceEventArgs e)
 {
     DeviceFound?.Invoke(sender, e);
 }
コード例 #26
0
ファイル: PmpSearcher.cs プロジェクト: nikropht/NBitcoin
 private void OnDeviceFound(DeviceEventArgs args)
 {
     if (DeviceFound != null)
         DeviceFound(this, args);
 }
コード例 #27
0
ファイル: ClientManager.cs プロジェクト: naiduv/Patchy
 void NatUtility_DeviceFound(object sender, DeviceEventArgs e)
 {
     try
     {
         e.Device.CreatePortMap(new Mapping(Protocol.Tcp, SettingsManager.IncomingPort, SettingsManager.IncomingPort));
         NatUtility.StopDiscovery();
     }
     catch { }
 }
コード例 #28
0
 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();
 }
コード例 #29
0
 /// <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 });
 }
コード例 #30
0
        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);
            }
        }
コード例 #31
0
ファイル: NatService.cs プロジェクト: einsteinx2/WaveBox
        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);
            }
        }