예제 #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);
            }
        }