示例#1
0
 protected override void SetEnabled(bool value)
 {
     if (value)
     {
         foreach (var localIp in _ipAddresses)
         {
             var individualSniffer = new IpSnifferRawSocketSingleInterface(localIp);
             individualSniffer.PacketReceived += OnPacketReceived;
             _individualSniffers.Add(individualSniffer);
         }
         foreach (var individualSniffer in _individualSniffers)
         {
             individualSniffer.Enabled = true;
         }
     }
     else
     {
         foreach (var individualSniffer in _individualSniffers)
         {
             individualSniffer.Enabled = false;
         }
         _individualSniffers.Clear();
     }
 }
 protected override void SetEnabled(bool value)
 {
     if (value)
     {
         foreach (var localIp in _ipAddresses)
         {
             var individualSniffer = new IpSnifferRawSocketSingleInterface(localIp);
             individualSniffer.PacketReceived += OnPacketReceived;
             _individualSniffers.Add(individualSniffer);
         }
         foreach (var individualSniffer in _individualSniffers)
         {
             individualSniffer.Enabled = true;
         }
     }
     else
     {
         foreach (var individualSniffer in _individualSniffers)
         {
             individualSniffer.Enabled = false;
         }
         _individualSniffers.Clear();
     }
 }
示例#3
0
        public void Initialize()
        {
            Task.Factory.StartNew(() =>
            {
                lock (_snifferLock)
                {
                    if (_teraSniffer != null)
                    {   //dereference the existing sniffer if it exists
                        var sniffer = _teraSniffer;
                        _teraSniffer = null;
                        sniffer.Enabled = false;
                        sniffer.MessageReceived -= HandleMessageReceived;
                        sniffer.NewConnection -= HandleNewConnection;
                        Logger.Info("Sniffer has been disabled.");
                    }

                    IpSniffer ipSniffer = null;
                    if (UseRawSockets && LocalIpAddress != null)
                    {
                        ipSniffer = new IpSnifferRawSocketSingleInterface(LocalIpAddress);
                    }

                    _teraSniffer = new TeraSniffer(ipSniffer, BasicTeraData.Servers);
                    _teraSniffer.MessageReceived += HandleMessageReceived;
                    _teraSniffer.NewConnection += HandleNewConnection;
                    _teraSniffer.Enabled = true;

                    Logger.Info("Sniffer has been enabled.");
                }
            }, TaskCreationOptions.LongRunning);//provide hint to start on new thread
        }