コード例 #1
0
ファイル: IPScanner.cs プロジェクト: hjohneny/PingU
        private bool StartNext(PingerEntry pinger)
        {
            if (_nextToScan == null)
            {
                return(false);
            }

            if (_aliveHosts.ContainsKey(_nextToScan))
            {
                IPScanHostState results = _aliveHosts[_nextToScan];
                results.Prepare();

                pinger._results = results;
            }
            else
            {
                pinger._results = new IPScanHostState(_nextToScan, _pingsPerScan, _timeout);
            }

            RaiseOnScanProgressUpdate(_nextToScan);

            _nextToScan = _range.GetNext(_nextToScan);

            _activePings++;
            pinger._ping.SendAsync(pinger._results.Address, _timeout, _pingBuffer, _pingOptions, pinger);

            return(true);
        }
コード例 #2
0
ファイル: IPScanner.cs プロジェクト: hjohneny/PingU
 private void RaiseOnAliveHostFound(IPScanHostState host)
 {
     if (OnAliveHostFound != null)
     {
         OnAliveHostFound(this, host);
     }
 }
コード例 #3
0
ファイル: IPScanner.cs プロジェクト: hjohneny/PingU
        void pinger_PingCompleted(object sender, PingCompletedEventArgs e)
        {
            PingerEntry     pinger  = (PingerEntry)e.UserState;
            IPScanHostState results = pinger._results;

            bool raiseEvent = false;

            results.StorePingResult(e.Reply.Status == IPStatus.Success ? e.Reply.RoundtripTime : -1);

            lock (_resultsLock)
            {
                if (!results.IsTesting())
                {
                    if (results.IsAlive())
                    {
                        raiseEvent = !_aliveHosts.ContainsKey(results.Address);

                        if (raiseEvent)
                        {
                            _aliveHosts.Add(results.Address, results);
                        }
                    }
                    else
                    {
                        _aliveHosts.Remove(results.Address);
                    }

                    --_activePings;

                    if (!_active)
                    {
                        if (_activePings == 0)
                        {
                            _stopEvent.Set();
                            RaiseOnStopScan();
                        }
                    }
                    else
                    {
                        if (_nextToScan == null)
                        {
                            if (_activePings == 0)
                            {
                                if (_continuousScan)
                                {
                                    RaiseOnRestartScan();
                                    Restart();
                                }
                                else
                                {
                                    _active = false;
                                    _stopEvent.Set();

                                    RaiseOnStopScan();
                                }
                            }
                        }
                        else
                        {
                            StartNext(pinger);
                        }
                    }
                }
                else
                {
                    pinger._ping.SendAsync(pinger._results.Address, _timeout, _pingBuffer, _pingOptions, pinger);
                }
            }

            if (raiseEvent)
            {
                RaiseOnAliveHostFound(results);
            }
        }