Ping a host machine to check uptime in C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace ProgramSendPingtoHost
{
    class ProgramSendPingtoHost
    {
        static void Main(string[] args)
        {
            try
            {
                string hostAddress = "127.0.0.1";
                System.Net.NetworkInformation.Ping ping = new System.Net.NetworkInformation.Ping();
                System.Net.NetworkInformation.PingReply reply = ping.Send(hostAddress);
                Console.WriteLine("The Host Address: {0}", reply.Address);
                Console.WriteLine("Status of the ping: {0}", reply.Status);
                Console.Read();
            }
            catch (Exception ex)
            {
            }
        }
    }
}

Output:

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.