public void Initialize(Nic targetNic, IPAddress from = null, IPAddress to = null) { if (from == null) from = targetNic.Ip.V4.PrimaryUnicast.Network.FirstAddress; if (to == null) to = targetNic.Ip.V4.PrimaryUnicast.Network.LastAddress; uint firstUint = BitConverter.ToUInt32(from.GetAddressBytes().Reverse().ToArray(), 0); uint lastUint = BitConverter.ToUInt32(to.GetAddressBytes().Reverse().ToArray(), 0); //for (uint i = firstUint; i <= lastUint; i++) for (uint i = firstUint; i <= lastUint; i++) { var ipAddress = new IPAddress(BitConverter.GetBytes(i).Reverse().ToArray()); var observer = new HostObserver(ipAddress, targetNic.Ip.V4.PrimaryUnicast.Address); observer.Options = Options.HostObserver; //hostChangeDetector.Options.Dns.DnsServer = targetNic.Raw.IpProperties.DnsAddresses.FirstOrDefault(x => x.AddressFamily == AddressFamily.InterNetwork); observer.State.ObserverSucceeded += ObserverSucceeded; observer.State.Activated += ObserverActivated; observer.State.Deactivated += ObserverDeactivated; _detectors.Add(observer); } Results.SetLocalNic(targetNic); }
private void ObserverSucceeded(HostObserver sender) { sender.State.ObserverSucceeded -= ObserverSucceeded; Application.Current.Dispatcher.InvokeAsync(() => _wasOnlineHosts.Add(sender)); }
private void ObserverDeactivated(HostObserver sender) { lock (_resultLock) { _triggerTimer.Stop(); Results.ScanDeactivated(); if (Results.ActiveScans == 0) { State.SetDeactivated(); } } }
private void ObserverActivated(HostObserver sender) { lock (_resultLock) { if (Results.ActiveScans == 0) { State.SetActivated(); } Results.ScanActivated(); } }