コード例 #1
0
        public static void Start(string address, CancellationToken cancellationToken)
        {
            PingAttributes attrs = new PingAttributes();

            m_Address = address;

            // Verify address
            attrs.ResolvedAddress = 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;

            Ping p = new Ping(attrs, cancellationToken, ResultsUpdateCallback);

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

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

            // Display results
            Display.ShowOutput = true;
            Display.PingResults(attrs, results);
        }
コード例 #2
0
        /// <summary>
        /// Sends a set of ping packets, results are stores within
        /// Ping.Results of the called object
        ///
        /// Acts as a basic wrapper to SendICMP and feeds it a specific
        /// set of PingAttributes
        /// </summary>
        public PingResults Send(PingAttributes attrs, Action <PingResults> onResultsUpdate = null)
        {
            // Lookup host if specified
            if (attrs.InputtedAddress != "")
            {
                attrs.Address = Lookup.QueryDNS(attrs.InputtedAddress, attrs.ForceV4 ? AddressFamily.InterNetwork : AddressFamily.InterNetworkV6);
            }

            Display.PingIntroMsg(attrs);

            if (Display.UseResolvedAddress)
            {
                try {
                    attrs.InputtedAddress = Helper.RunWithCancellationToken(() => Lookup.QueryHost(attrs.Address), m_CancellationToken);
                } catch (OperationCanceledException) {
                    return(new PingResults());
                }
                if (attrs.InputtedAddress == "")
                {
                    // If reverse lookup fails just display whatever is in the address field
                    attrs.InputtedAddress = attrs.Address;
                }
            }

            // Perform ping operation and store results
            PingResults results = SendICMP(attrs, onResultsUpdate);

            if (Display.ShowOutput)
            {
                Display.PingResults(attrs, results);
            }

            return(results);
        }
コード例 #3
0
ファイル: Flood.cs プロジェクト: mBr001/PowerPing
        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);
        }
コード例 #4
0
ファイル: Ping.cs プロジェクト: jdpurcell/PowerPing
        /// <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);
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: samuelriesz/PowerPing
        /// <summary>
        /// Main entry point of PowerPing
        /// Parses arguments and runs operations
        /// </summary>
        /// <param name="args">Program arguments</param>
        static void Main(string[] args)
        {
            // User inputted attributes
            PingAttributes inputtedAttributes = new PingAttributes();

            // Setup console
            Display.DefaultForegroundColor = Console.ForegroundColor;
            Display.DefaultBackgroundColor = Console.BackgroundColor;

            // Show current version info
            //Display.Version();

            // Check if no arguments
            if (args.Length == 0)
            {
                Display.Help();
                Helper.WaitForUserInput();
                return;
            }

            // Parse command line arguments
            if (!CommandLine.Parse(args, ref inputtedAttributes))
            {
                Helper.ErrorAndExit("Problem parsing arguments, use \"PowerPing /help\" or \"PowerPing /?\" for help.");
            }

            // Find address/host in arguments
            if (inputtedAttributes.Operation != PingOperation.Whoami &&
                inputtedAttributes.Operation != PingOperation.Listen)
            {
                if (!CommandLine.FindAddress(args, ref inputtedAttributes))
                {
                    Helper.ErrorAndExit("Could not find correctly formatted address, please check and try again");
                }
            }

            // Perform DNS lookup on inputted address
            // inputtedAttributes.ResolvedAddress = Lookup.QueryDNS(inputtedAttributes.InputtedAddress, inputtedAttributes.UseICMPv4 ? AddressFamily.InterNetwork : AddressFamily.InterNetworkV6);

            // Add Control C event handler
            if (inputtedAttributes.Operation != PingOperation.Whoami &&
                inputtedAttributes.Operation != PingOperation.Location &&
                inputtedAttributes.Operation != PingOperation.Whois)
            {
                Console.CancelKeyPress += new ConsoleCancelEventHandler(ExitHandler);
            }

            // Select correct function using opMode
            Ping  p;
            Graph g;

            switch (inputtedAttributes.Operation)
            {
            case PingOperation.Listen:
                // If we find an address then pass it to listen, otherwise start it without one
                if (CommandLine.FindAddress(args, ref inputtedAttributes))
                {
                    Listen.Start(m_CancellationTokenSource.Token, inputtedAttributes.InputtedAddress);
                }
                else
                {
                    Listen.Start(m_CancellationTokenSource.Token);
                }
                break;

            case PingOperation.Location:
                Console.WriteLine(Lookup.GetAddressLocationInfo(inputtedAttributes.InputtedAddress, false));
                Helper.WaitForUserInput();
                break;

            case PingOperation.Whoami:
                Console.WriteLine(Lookup.GetAddressLocationInfo("", true));
                Helper.WaitForUserInput();
                break;

            case PingOperation.Whois:
                Lookup.QueryWhoIs(inputtedAttributes.InputtedAddress);
                break;

            case PingOperation.Graph:
                g = new Graph(inputtedAttributes.InputtedAddress, m_CancellationTokenSource.Token);
                g.Start();
                break;

            case PingOperation.CompactGraph:
                g = new Graph(inputtedAttributes.InputtedAddress, m_CancellationTokenSource.Token);
                g.CompactGraph = true;
                g.Start();
                break;

            case PingOperation.Flood:
                Flood.Start(inputtedAttributes.InputtedAddress, m_CancellationTokenSource.Token);
                break;

            case PingOperation.Scan:
                Scan.Start(inputtedAttributes.InputtedAddress, m_CancellationTokenSource.Token);
                break;

            case PingOperation.Normal:
                // Send ping normally
                p = new Ping(inputtedAttributes, m_CancellationTokenSource.Token);
                PingResults results = p.Send();
                Display.PingResults(inputtedAttributes, results);
                break;

            default:
                Helper.ErrorAndExit("Could not determine ping operation");
                break;
            }

            // Reset console colour
            Display.ResetColor();
            try { Console.CursorVisible = true; } catch (Exception) { }
        }