Is Internet Connection Available : Ping « Network « C# / C Sharp






Is Internet Connection Available

        

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.NetworkInformation;

namespace Common {
  public static class MailHelper {

    public static bool InternetConnectionAvailable( ) {
      bool result = false;
      Ping ping = new Ping( );
      PingReply reply = null;
      try {
        reply = ping.Send( "www.google.com" );
        result = reply.Status == IPStatus.Success;
      } catch ( Exception ) {

      }

      return result;
    }

  }
}

   
    
    
    
    
    
    
    
  








Related examples in the same category

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