/// <summary> /// Stores graph drawing loop /// </summary> private void Draw() { // Start ping in background thread Thread pinger = new Thread(() => graphPing.Send(graphPingAttrs)); pinger.IsBackground = true; pinger.Start(); running = true; // Drawing loop while (true) { // Stop look if we get a cancel flag if (cancelFlag) { break; } // Reset position Console.CursorTop = plotStartY; Console.CursorLeft = plotStartX; // Draw graph columns DrawGraphColumns(); // Update labels UpdateLabels(graphPing.Results); // Get results from ping and add to graph AddColumnToGraph(CreateColumn(graphPing.Results.CurTime)); Console.CursorTop = EndCursorPosY; // Wait one second Thread.Sleep(1000); } // Clean up running = false; graphPing.Dispose(); pinger.Abort(); }
/// <summary> /// Sends high volume of ping packets /// </summary> public void Flood(string address) { PingAttributes attrs = new PingAttributes(); Ping p = new Ping(); // Verify address attrs.Address = PowerPing.Lookup.QueryDNS(address, AddressFamily.InterNetwork); // Setup ping attributes attrs.Interval = 0; attrs.Timeout = 100; attrs.Message = "R U Dead Yet?"; attrs.Continous = true; // Disable output for faster speeds Display.ShowOutput = false; // Start flood thread var thread = new Thread(() => { p.Send(attrs); }); thread.IsBackground = true; thread.Start(); IsRunning = true; // Results loop while (IsRunning) { // Update results text Display.FloodProgress(p.Results, address); // Wait before updating (save our CPU load) and check for cancel event if (cancelEvent.WaitOne(1000)) { break; } } // Cleanup IsRunning = false; p.Dispose(); thread.Abort(); // Display results Display.PingResults(p); }
/// <summary> /// Runs when Exit or Cancel event fires (normally when Ctrl-C) /// is pressed. Used to clean up and stop operations when exiting /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private static void ExitHandler(object sender, ConsoleCancelEventArgs args) { // Cancel termination args.Cancel = true; // Stop ping p.Dispose(); // Stop graph if it is running if (g != null) { g.Dispose(); } // Reset console colour Display.ResetColor(); Console.CursorVisible = true; }