using System.Net.NetworkInformation;
string remoteMachineNameOrIP = "127.0.0.1";
    int timeOut = 5;
    Ping ping = new Ping();
    // Pinging remote maching
    PingReply reply = ping.Send(remoteMachineNameOrIP, timeOut);
    // Displaying the result
    StringBuilder sb = new StringBuilder();
    sb.Append("Address:" + reply.Address.ToString());
    sb.Append("\nStatus:" + reply.Status.ToString());
    sb.Append("\nRoundtripTime:" + reply.RoundtripTime.ToString());
    MessageBox.Show(sb.ToString(), "Ping Result: " + remoteMachineNameOrIP);