Success : Ping « Network « C# / C Sharp






Success

  

using System;
using System.Net.NetworkInformation;

class MainClass {
    public static void Main(string[] args) {
        using (Ping ping = new Ping()) {
            Console.WriteLine("Pinging:");

            foreach (string comp in args) {
                try {
                    Console.Write("    {0}...", comp);
                    PingReply reply = ping.Send(comp, 100);
                    if (reply.Status == IPStatus.Success) {
                        Console.WriteLine("Success - IP Address:{0}", reply.Address, reply.RoundtripTime);
                    } else {
                        Console.WriteLine(reply.Status);
                    }
                } catch (Exception ex) {
                    Console.WriteLine("Error ({0})",
                        ex.InnerException.Message);
                }
            }
        }
    }
}

   
  








Related examples in the same category

1.Ping and PingReply
2.Ping Success and Send
3.Advanced Ping ProgramAdvanced Ping Program
4.Simple Ping
5.This method checks if there is a connection at all
6.Ping a host
7.Uses the System.Net.NetworkInformation.Ping class to send an ICMP ping to a specified host asynchronously.
8.Is Internet Connection Available