Click here to Skip to main content
15,880,796 members
Articles / Web Development / ASP.NET
Alternative
Tip/Trick

Checking Internet Is Connected Or Not From .NET

Rate me:
Please Sign up or sign in to vote.
4.87/5 (34 votes)
16 May 2011CPOL 24.4K   12   14
For C# guys....using System ;using System.Runtime ;using System.Runtime.InteropServices ;public class Internet{ [DllImport("wininet.dll")] private extern static bool InternetGetConnectedState( out int Description, int ReservedValue ) ; public static bool...
For C# guys....

using System ;
using System.Runtime ;
using System.Runtime.InteropServices ;

public class Internet
{

    [DllImport("wininet.dll")]
    private extern static bool InternetGetConnectedState( out int Description, int ReservedValue ) ;

    public static bool IsConnectedToInternet( )
    {
        int Desc ;
        return InternetGetConnectedState( out Desc, 0 ) ;
    }
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) NA
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 5 Pin
Mykola Panas K.1-Feb-13 2:35
professionalMykola Panas K.1-Feb-13 2:35 
GeneralMy vote of 5 Pin
Oshtri Deka14-Jun-12 3:26
professionalOshtri Deka14-Jun-12 3:26 
GeneralReason for my vote of 5 Simple and Effective... Pin
Pravin Patil, Mumbai7-Oct-11 8:31
Pravin Patil, Mumbai7-Oct-11 8:31 
GeneralHood :) Pin
Anshul R25-May-11 21:34
Anshul R25-May-11 21:34 
GeneralReason for my vote of 5 Good :) Pin
Anshul R25-May-11 21:34
Anshul R25-May-11 21:34 
Reason for my vote of 5
Good Smile | :)
GeneralReason for my vote of 5 Nice simple clean Pin
L Viljoen25-May-11 2:59
professionalL Viljoen25-May-11 2:59 
Generalif u need the code vb.net refer this Private Declare Funct... Pin
bisharbn16-May-11 5:09
bisharbn16-May-11 5:09 
GeneralReason for my vote of 5 Nice and simple... Pin
Rhuros16-May-11 2:21
professionalRhuros16-May-11 2:21 
GeneralReason for my vote of 3 see my previous comment Pin
charles henington29-Apr-11 13:49
charles henington29-Apr-11 13:49 
GeneralWorks just fine brain i've even checked myself although one ... Pin
charles henington29-Apr-11 13:48
charles henington29-Apr-11 13:48 
Generalit doesn't work Pin
Sameh Marzok26-Apr-11 1:02
Sameh Marzok26-Apr-11 1:02 
GeneralReason for my vote of 4 Easy way Pin
demouser74322-Apr-11 3:25
demouser74322-Apr-11 3:25 
GeneralReason for my vote of 2 u can directly ping any site without... Pin
--K O-- Solutions18-Apr-11 23:41
--K O-- Solutions18-Apr-11 23:41 
GeneralReason for my vote of 5 simpler Pin
fdunn318-Apr-11 16:14
fdunn318-Apr-11 16:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.