CGC_Codes

Ping and Ping reply

Mar 13th, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.81 KB | None | 0 0
  1. using System;
  2. using System.Net.NetworkInformation;
  3.  
  4. class MainClass {
  5.     public static void Main(string[] args) {
  6.         using (Ping ping = new Ping()) {
  7.             foreach (string comp in args) {
  8.                 try {
  9.                     Console.Write("    {0}...", comp);
  10.                     PingReply reply = ping.Send(comp, 100);
  11.                     if (reply.Status == IPStatus.Success) {
  12.                         Console.WriteLine("Success - IP Address:{0}", reply.Address, reply.RoundtripTime);
  13.                     } else {
  14.                         Console.WriteLine(reply.Status);
  15.                     }
  16.                 } catch (Exception ex) {
  17.                     Console.WriteLine("Error ({0})",
  18.                         ex.InnerException.Message);
  19.                 }
  20.             }
  21.         }
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment