Ping

C#-ban készült Ping, ICMP csomagok küldése a hoszt ellenőrzéséhez. (forrás)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.NetworkInformation;
 
namespace myPing
{
    class Program
    {
        static void Main(string[] args)
        {
                try
                {
                    if (args.Length == 0)
                        throw new ArgumentException("Ping-hez szükséges egy host név vagy egy IP cím.");
 
                    Ping icmpSign = new Ping();
                    PingOptions options = new PingOptions();
                    options.DontFragment = true;
                    string data = "datadatadatadatadatadatadatadata"; //32 byte
                    byte[] buffer = Encoding.ASCII.GetBytes(data);
                    int timeout = 120;
                    PingReply reply = icmpSign.Send(args[0], timeout, buffer, options);
                    if (reply.Status == IPStatus.Success)
                    {
                        Console.WriteLine("Address: {0}", reply.Address.ToString());
                        Console.WriteLine("RoundTrip time: {0}", reply.RoundtripTime);
                        Console.WriteLine("Time to live: {0}", reply.Options.Ttl);
                        Console.WriteLine("Don't fragment: {0}", reply.Options.DontFragment);
                        Console.WriteLine("Buffer size: {0}", reply.Buffer.Length);
                        System.Console.In.ReadLine();
                    }
                    else
                    {
                        Console.WriteLine("Sikertelen lekérdezés.");
                        System.Console.In.ReadLine();
                    }
                }
                catch (System.ArgumentException ex)
                {
                    Console.WriteLine(ex.Message);
                }
        }
    }
}