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); }
/// <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); }
// This callback will run after each ping iteration private static 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), m_Address); }