2011-09-27

Codigo: Hacer ping


Un ejemplo mas de código en esta ocasión como comprobar si un host esta disponibles para el uso en nuestra aplicación:



public static int Ping(string hostname){
 
Ping ping = new Ping();

 
PingReply reply = ping.Send(hostname);
 
if (reply.Status == IPStatus.Success){
  
Console.WriteLine("Address: {0}", reply.Address);
  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);
  Console.WriteLine("Status: {0}", reply.Status);
  Console.ReadLine();
  return (0);
 
}
 
else {
  
Console.WriteLine("Error");
  
Console.WriteLine("Status: {0}", reply.Status);
  
Console.ReadLine();
  return (1);
 } 
}