Pinging localhost [Answered]

The block below is a method that compiles without issue. However, when I try and pass it localhost:8888 it skips over the pingable = reply.Status == IPStatus.Success line into the catch. Am I passing the argument wrong or do I need a different method to handle local host?

public static bool PingHost(string nameOrAddress)
    {
        bool pingable = false;
        Ping pinger = null;

        try
        {
            pinger = new Ping();
            PingReply reply = pinger.Send(nameOrAddress);
            pingable = reply.Status == IPStatus.Success;
        }
        catch (PingException)
        {
            // Discard PingExceptions and return false;
        }
        finally
        {
            if (pinger != null)
            {
                pinger.Dispose();
            }
        }

        return pingable;
    }
Was this page helpful?