Ping Demo : Ping : Network C# Examples


C# Examples » Network » Ping »

 

Ping Demo









    
using  System;
using  System.Net.NetworkInformation;

class  MainClass
{
        public  static  void  Main(string[]  args)
        {
                using  (Ping  ping  =  new  Ping())
                {
                          try
                          {
                                  PingReply  reply  =  ping.Send("127.0.0.1",  100);

                                  if  (reply.Status  ==  IPStatus.Success)
                                  {
                                      Console.WriteLine("Success  -  IP  Address:{0}  Time:{1}ms",
                                              reply.Address,  reply.RoundtripTime);
                                  }
                                  else
                                  {
                                          Console.WriteLine(reply.Status);
                                  }
                          }
                          catch  (Exception  ex)
                          {
                                  Console.WriteLine("Error  ({0})",  ex.InnerException.Message);
                          }
                }
        }
}
    
   
  
   



Output

Success - IP Address:127.0.0.1 Time:0ms


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Network
» Ping