Common network functions.
Beispiel #1
0
        /// <summary>
        /// Attempts to ping a host.
        /// </summary>
        /// <param name="hostname">Host to ping</param>
        /// <param name="pingCount">Ping count</param>
        /// <returns>Ping results</returns>
        public PingResponse PingHost(string hostname, int pingCount)
        {
            IPHostEntry host = NetworkUtilities.ResolveHost(hostname);

            if (host == null)
            {
                OnPingError(PingResponseType.CouldNotResolveHost, "Could not resolve the host '" + hostname + "'");

                PingResponse response = new PingResponse();
                response.PingResult   = PingResponseType.CouldNotResolveHost;
                response.ErrorMessage = "Could not resolve the host '" + hostname + "'";

                return(response);
            }
            else
            {
                return(PingHost(new IPEndPoint(host.AddressList[0], 0), pingCount));
            }
        }