Esempio n. 1
0
        private void _scanner_OnStartScan(IPScanner scanner)
        {
            if (InvokeRequired)
            {
                BeginInvoke(new IPScanner.ScanStateChangeDelegate(_scanner_OnStartScan), scanner);
                return;
            }

            foreach (ListViewItem item in _lvAliveHosts.Items)
            {
                ((IPScanHostState)item.Tag).OnStateChange       -= host_OnStateChange;
                ((IPScanHostState)item.Tag).OnHostNameAvailable -= host_OnHostNameAvailable;
            }

            _lvAliveHosts.Items.Clear();
            _lbLog.Items.Clear();

            _btnAddHost.Enabled = _btnTrace.Enabled = false;

            AddLogEntry("Scanning has been started!");

            _prgScanProgress.Value = 0;

            EnableSettings(false);
        }
Esempio n. 2
0
        private void submitBtn_Click(object sender, EventArgs e)
        {
            IPScanner scanner = new IPScanner();

            scanner.IPScanned += this.Scanner_IPScanned;
            scanner.ScanRange(startText.Text, endText.Text);
        }
        private async void StartScan()
        {
            DisplayStatusMessage = false;
            IsScanRunning        = true;
            PreparingScan        = true;

            // Measure the time
            StartTime = DateTime.Now;
            stopwatch.Start();
            dispatcherTimer.Tick    += DispatcherTimer_Tick;
            dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 100);
            dispatcherTimer.Start();
            EndTime = null;

            IPScanResult.Clear();
            HostsFound = 0;

            cancellationTokenSource = new CancellationTokenSource();

            IPAddress[] ipAddresses;

            try
            {
                // Create a list of all ip addresses
                ipAddresses = await IPScanRangeHelper.ConvertIPRangeToIPAddressesAsync(IPRange, cancellationTokenSource.Token);
            }
            catch (OperationCanceledException)
            {
                IpScanner_UserHasCanceled(this, EventArgs.Empty);
                return;
            }

            IPAddressesToScan  = ipAddresses.Length;
            IPAddressesScanned = 0;

            PreparingScan = false;

            // Add the range to the history
            AddIPRangeToHistory(IPRange);

            IPScannerOptions ipScannerOptions = new IPScannerOptions
            {
                Threads           = SettingsManager.Current.IPScanner_Threads,
                Timeout           = SettingsManager.Current.IPScanner_Timeout,
                Buffer            = new byte[SettingsManager.Current.IPScanner_Buffer],
                Attempts          = SettingsManager.Current.IPScanner_Attempts,
                ResolveHostname   = SettingsManager.Current.IPScanner_ResolveHostname,
                ResolveMACAddress = SettingsManager.Current.IPScanner_ResolveMACAddress,
                ShowScanResultForAllIPAddresses = SettingsManager.Current.IPScanner_ShowScanResultForAllIPAddresses
            };

            IPScanner ipScanner = new IPScanner();

            ipScanner.HostFound       += IpScanner_HostFound;
            ipScanner.ScanComplete    += IpScanner_ScanComplete;
            ipScanner.ProgressChanged += IpScanner_ProgressChanged;
            ipScanner.UserHasCanceled += IpScanner_UserHasCanceled;

            ipScanner.ScanAsync(ipAddresses, ipScannerOptions, cancellationTokenSource.Token);
        }
Esempio n. 4
0
        public ScanAddIP()
        {
            InitializeComponent();
            _scanner = new IPScanner(64, 2, false, 1500, 32, false, 32);

            _scanner.OnAliveHostFound += new IPScanner.AliveHostFoundDelegate(_scanner_OnAliveHostFound);

            _scanner.OnStartScan          += new IPScanner.ScanStateChangeDelegate(_scanner_OnStartScan);
            _scanner.OnStopScan           += new IPScanner.ScanStateChangeDelegate(_scanner_OnStopScan);
            _scanner.OnRestartScan        += new IPScanner.ScanStateChangeDelegate(_scanner_OnRestartScan);
            _scanner.OnScanProgressUpdate += new IPScanner.ScanProgressUpdateDelegate(_scanner_OnScanProgressUpdate);
        }
Esempio n. 5
0
        void _scanner_OnScanProgressUpdate(IPScanner scanner, IPAddress currentAddress, ulong progress, ulong total)
        {
            if (InvokeRequired)
            {
                BeginInvoke(new IPScanner.ScanProgressUpdateDelegate(_scanner_OnScanProgressUpdate), scanner, currentAddress, progress, total);
                return;
            }

            int prog = (int)((100 * progress) / total);

            _prgScanProgress.Value = prog;
            _prgScanProgress.Text  = prog.ToString() + "%" + " [" + currentAddress.ToString() + "]";
        }
Esempio n. 6
0
 public IPScan()
 {
     InitializeComponent();
     _scanner = new IPScanner((int)_spnConcurrentPings.Value, (int)_spnPingsPerScan.Value, false,
                              (int)_spnTimeout.Value, (int)_spnTTL.Value, false, (int)_spnBufferSize.Value);
     _scanner.OnAliveHostFound       += new IPScanner.AliveHostFoundDelegate(_scanner_OnAliveHostFound);
     _scanner.OnStartScan            += new IPScanner.ScanStateChangeDelegate(_scanner_OnStartScan);
     _scanner.OnStopScan             += new IPScanner.ScanStateChangeDelegate(_scanner_OnStopScan);
     _scanner.OnRestartScan          += new IPScanner.ScanStateChangeDelegate(_scanner_OnRestartScan);
     _scanner.OnScanProgressUpdate   += new IPScanner.ScanProgressUpdateDelegate(_scanner_OnScanProgressUpdate);
     _lvAliveHosts.ListViewItemSorter = new HostSorterByIP();
     _cmbRangeType.SelectedIndex      = 0;
 }
Esempio n. 7
0
        void _scanner_OnRestartScan(IPScanner scanner)
        {
            if (InvokeRequired)
            {
                BeginInvoke(new IPScanner.ScanStateChangeDelegate(_scanner_OnRestartScan), scanner);
                return;
            }

            AddLogEntry("Scaned!");
            AddLogEntry("Hosts found : " + _scanner.AliveHosts.Count);
            AddLogEntry("Rescan!");
            _prgScanProgress.Value = 0;
        }
Esempio n. 8
0
        private void _scanner_OnStopScan(IPScanner scanner)
        {
            if (InvokeRequired)
            {
                BeginInvoke(new IPScanner.ScanStateChangeDelegate(_scanner_OnStopScan), scanner);
                return;
            }
            EnableSettings(true);

            AddLogEntry("Finished Scanning!");
            AddLogEntry("Hosts found: " + _scanner.AliveHosts.Count);
            _prgScanProgress.Value = 0;
        }
Esempio n. 9
0
        /// <summary>
        /// Scans the local network and synchronizes the located systems details with the
        /// configured <c>Snipe.It</c> system.
        /// </summary>
        private void SyncScannerDetails()
        {
            var scannerSubnets =
                ConfigurationManager
                .AppSettings["Marksman:ScannerSubnet"]
                .Split("|".ToArray(), StringSplitOptions.RemoveEmptyEntries);

            var devices =
                IPScanner
                .Scan(scannerSubnets)
                .Where(i => i.Status == System.Net.NetworkInformation.IPStatus.Success)
                .ToList();

            foreach (var item in devices)
            {
                this.SyncHostNameDetails(item.HostName);
            }
        }
Esempio n. 10
0
        static void Main(string[] args)
        {
            var ipAddresses = IPScanner.ScanIPs();

            foreach (string ip in ipAddresses)
            {
                Console.WriteLine(string.Format("Responded with IP: {0}.", ip));
                //Scan ports
                var ports = PortScanner.Scan(ip, 0, 65000);
                foreach (var port in ports)
                {
                    Console.WriteLine(string.Format("Found open port: {0}", port.ToString()));
                }
            }



            Console.WriteLine("Scan Complete.");
        }
Esempio n. 11
0
        private void _scanner_OnAliveHostFound(IPScanner scanner, IPScanHostState host)
        {
            if (InvokeRequired)
            {
                BeginInvoke(new IPScanner.AliveHostFoundDelegate(_scanner_OnAliveHostFound), scanner, host);
                return;
            }

            ListViewItem item = new ListViewItem();

            item.Tag = host;

            item.BackColor = Color.GreenYellow;
            item.SubItems.Add(host.Address.ToString());
            item.SubItems.Add("");
            item.SubItems.Add("");
            item.SubItems.Add("");

            _lvAliveHosts.Items.Add(item);
            _lvAliveHosts.Sort();

            host.OnHostNameAvailable += new IPScanHostState.HostNameAvailableDelegate(host_OnHostNameAvailable);
            host.OnStateChange       += new IPScanHostState.StateChangeDelegate(host_OnStateChange);

            if (!host.IsTesting())
            {
                item.ImageIndex       = (int)host.QualityCategory;
                item.SubItems[2].Text = host.AvgResponseTime.ToString("F02") + " ms";
                item.SubItems[3].Text = ((float)(host.LossCount) / host.PingsCount).ToString("P");
                item.SubItems[4].Text = host.HostName;
            }

            AddLogEntry("Host [" + host.Address.ToString() + "] is alive.");

            Timer newTimer = new Timer();

            newTimer.Tag      = item;
            newTimer.Interval = 2000;
            newTimer.Tick    += new EventHandler(newTimer_Tick);

            newTimer.Enabled = true;
        }
Esempio n. 12
0
        private async void StartScan()
        {
            DisplayStatusMessage = false;
            IsScanRunning        = true;
            PreparingScan        = true;

            // Measure the time
            StartTime = DateTime.Now;
            stopwatch.Start();
            dispatcherTimer.Tick    += DispatcherTimer_Tick;
            dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 100);
            dispatcherTimer.Start();
            EndTime = null;

            IPScanResult.Clear();
            HostsFound = 0;

            // Change the tab title (not nice, but it works)
            Window window = Application.Current.Windows.OfType <Window>().FirstOrDefault(x => x.IsActive);

            if (window != null)
            {
                foreach (TabablzControl tabablzControl in VisualTreeHelper.FindVisualChildren <TabablzControl>(window))
                {
                    tabablzControl.Items.OfType <DragablzTabItem>().First(x => x.ID == _tabId).Header = IPRange;
                }
            }

            cancellationTokenSource = new CancellationTokenSource();

            IPAddress[] ipAddresses;

            try
            {
                // Create a list of all ip addresses
                ipAddresses = await IPScanRangeHelper.ConvertIPRangeToIPAddressesAsync(IPRange, cancellationTokenSource.Token);
            }
            catch (OperationCanceledException)
            {
                IpScanner_UserHasCanceled(this, EventArgs.Empty);
                return;
            }

            IPAddressesToScan  = ipAddresses.Length;
            IPAddressesScanned = 0;

            PreparingScan = false;

            // Add the range to the history
            AddIPRangeToHistory(IPRange);

            IPScannerOptions ipScannerOptions = new IPScannerOptions
            {
                Threads           = SettingsManager.Current.IPScanner_Threads,
                Timeout           = SettingsManager.Current.IPScanner_Timeout,
                Buffer            = new byte[SettingsManager.Current.IPScanner_Buffer],
                Attempts          = SettingsManager.Current.IPScanner_Attempts,
                ResolveHostname   = SettingsManager.Current.IPScanner_ResolveHostname,
                ResolveMACAddress = SettingsManager.Current.IPScanner_ResolveMACAddress,
                ShowScanResultForAllIPAddresses = SettingsManager.Current.IPScanner_ShowScanResultForAllIPAddresses
            };

            IPScanner ipScanner = new IPScanner();

            ipScanner.HostFound       += IpScanner_HostFound;
            ipScanner.ScanComplete    += IpScanner_ScanComplete;
            ipScanner.ProgressChanged += IpScanner_ProgressChanged;
            ipScanner.UserHasCanceled += IpScanner_UserHasCanceled;

            ipScanner.ScanAsync(ipAddresses, ipScannerOptions, cancellationTokenSource.Token);
        }
        private async void StartScan()
        {
            DisplayStatusMessage = false;
            IsScanRunning        = true;
            PreparingScan        = true;

            // Measure the time
            StartTime = DateTime.Now;
            stopwatch.Start();
            dispatcherTimer.Tick    += DispatcherTimer_Tick;
            dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 100);
            dispatcherTimer.Start();
            EndTime = null;

            IPScanResult.Clear();
            HostsFound = 0;

            // Change the tab title (not nice, but it works)
            Window window = Application.Current.Windows.OfType <Window>().FirstOrDefault(x => x.IsActive);

            if (window != null)
            {
                foreach (TabablzControl tabablzControl in VisualTreeHelper.FindVisualChildren <TabablzControl>(window))
                {
                    tabablzControl.Items.OfType <DragablzTabItem>().First(x => x.ID == _tabId).Header = IPRange;
                }
            }

            cancellationTokenSource = new CancellationTokenSource();

            string[] ipHostOrRanges = IPRange.Replace(" ", "").Split(';');

            // Resolve hostnames
            List <string> ipRanges = new List <string>();

            try
            {
                ipRanges = await IPScanRangeHelper.ResolveHostnamesInIPRangeAsync(ipHostOrRanges, cancellationTokenSource.Token);
            }
            catch (OperationCanceledException)
            {
                IpScanner_UserHasCanceled(this, EventArgs.Empty);
                return;
            }
            catch (AggregateException exceptions) // DNS error (could not resolve hostname...)
            {
                IpScanner_DnsResolveFailed(this, exceptions);
                return;
            }

            IPAddress[] ipAddresses;

            try
            {
                // Create a list of all ip addresses
                ipAddresses = await IPScanRangeHelper.ConvertIPRangeToIPAddressesAsync(ipRanges.ToArray(), cancellationTokenSource.Token);
            }
            catch (OperationCanceledException)
            {
                IpScanner_UserHasCanceled(this, EventArgs.Empty);
                return;
            }

            IPAddressesToScan  = ipAddresses.Length;
            IPAddressesScanned = 0;

            PreparingScan = false;

            // Add the range to the history
            AddIPRangeToHistory(IPRange);

            IPScannerOptions ipScannerOptions = new IPScannerOptions
            {
                Threads                         = SettingsManager.Current.IPScanner_Threads,
                ICMPTimeout                     = SettingsManager.Current.IPScanner_ICMPTimeout,
                ICMPBuffer                      = new byte[SettingsManager.Current.IPScanner_ICMPBuffer],
                ICMPAttempts                    = SettingsManager.Current.IPScanner_ICMPAttempts,
                ResolveHostname                 = SettingsManager.Current.IPScanner_ResolveHostname,
                UseCustomDNSServer              = SettingsManager.Current.IPScanner_UseCustomDNSServer,
                CustomDNSServer                 = SettingsManager.Current.IPScanner_CustomDNSServer.Select(x => x.Trim()).ToList(),
                DNSPort                         = SettingsManager.Current.IPScanner_DNSPort,
                DNSTransportType                = SettingsManager.Current.IPScanner_DNSTransportType,
                DNSRecursion                    = SettingsManager.Current.IPScanner_DNSRecursion,
                DNSUseResolverCache             = SettingsManager.Current.IPScanner_DNSUseResolverCache,
                DNSAttempts                     = SettingsManager.Current.IPScanner_DNSAttempts,
                DNSTimeout                      = SettingsManager.Current.IPScanner_DNSTimeout,
                ResolveMACAddress               = SettingsManager.Current.IPScanner_ResolveMACAddress,
                ShowScanResultForAllIPAddresses = SettingsManager.Current.IPScanner_ShowScanResultForAllIPAddresses
            };

            IPScanner ipScanner = new IPScanner();

            ipScanner.HostFound       += IpScanner_HostFound;
            ipScanner.ScanComplete    += IpScanner_ScanComplete;
            ipScanner.ProgressChanged += IpScanner_ProgressChanged;
            ipScanner.UserHasCanceled += IpScanner_UserHasCanceled;

            ipScanner.ScanAsync(ipAddresses, ipScannerOptions, cancellationTokenSource.Token);
        }