예제 #1
0
파일: Ping.cs 프로젝트: zanderphh/PowerPing
        public PingResults Send()
        {
            // Reset some properties so they are readyfor pinging
            Reset();

            Display.PingIntroMsg(m_PingAttributes);

            // TODO: I think this part is bullshit, check later
            if (Display.UseResolvedAddress)
            {
                try {
                    m_PingAttributes.InputtedAddress = Helper.RunWithCancellationToken(() => Lookup.QueryHost(m_PingAttributes.ResolvedAddress), m_CancellationToken);
                }
                catch (OperationCanceledException) {
                    return(new PingResults());
                }
                if (m_PingAttributes.InputtedAddress == "")
                {
                    // If reverse lookup fails just display whatever is in the address field
                    m_PingAttributes.InputtedAddress = m_PingAttributes.ResolvedAddress;
                }
            }

            // Peroform ping operation
            SendPacket();

            return(m_PingResults);
        }
예제 #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);
        }