Beispiel #1
0
        public static void Start(string address, CancellationToken cancellationToken)
        {
            PingAttributes attrs = new PingAttributes();
            RateLimiter    displayUpdateLimiter = new RateLimiter(TimeSpan.FromMilliseconds(500));
            ulong          previousPingsSent    = 0;
            Ping           p = new Ping(cancellationToken);

            // Verify address
            attrs.Address = Lookup.QueryDNS(address, AddressFamily.InterNetwork);;

            // Setup ping attributes
            attrs.Interval = 0;
            attrs.Timeout  = 100;
            attrs.Message  = "R U Dead Yet?";
            // TODO: Option for 'heavy' flood with bloated packet sizes
            attrs.Continous = true;

            // Disable output for faster speeds
            Display.ShowOutput = false;

            // This callback will run after each ping iteration
            void ResultsUpdateCallback(PingResults r)
            {
                // Make sure we're not updating the display too frequently
                if (!displayUpdateLimiter.RequestRun())
                {
                    return;
                }

                // Calculate pings per second
                double pingsPerSecond = 0;

                if (displayUpdateLimiter.ElapsedSinceLastRun != TimeSpan.Zero)
                {
                    pingsPerSecond = (r.Sent - previousPingsSent) / displayUpdateLimiter.ElapsedSinceLastRun.TotalSeconds;
                }
                previousPingsSent = r.Sent;

                // Update results text
                Display.FloodProgress(r.Sent, (ulong)Math.Round(pingsPerSecond), address);
            }

            // Start flooding
            PingResults results = p.Send(attrs, ResultsUpdateCallback);

            // Display results
            Display.ShowOutput = true;
            Display.PingResults(attrs, results);
        }
Beispiel #2
0
        /// <summary>
        /// Stores graph drawing loop
        /// </summary>
        private void Draw()
        {
            // The actual display update rate may be limited by the ping interval
            RateLimiter displayUpdateLimiter = new RateLimiter(TimeSpan.FromMilliseconds(500));

            // This callback will run after each ping iteration
            void ResultsUpdateCallback(PingResults r)
            {
                // Make sure we're not updating the display too frequently
                if (!displayUpdateLimiter.RequestRun())
                {
                    return;
                }

                int scalePrevious = m_Scale;

                // Reset position
                Console.CursorTop  = m_PlotStartY;
                Console.CursorLeft = m_PlotStartX;

                // Update labels
                UpdateLegend(r);

                // Get results from ping and add to graph
                AddResponseToGraph(r.CurrTime);

                // Draw graph columns
                DrawColumns();

                // Only draw the y axis labels if the scale has changed
                if (scalePrevious != m_Scale)
                {
                    DrawYAxisLabels();
                }

                Console.CursorTop = EndCursorPosY;
            }

            // Start pinging
            PingResults results = m_Ping.Send(m_PingAttributes, ResultsUpdateCallback);
        }