PC Review


Reply
Thread Tools Rate Thread

Internet Connection Check?

 
 
David Pope
Guest
Posts: n/a
 
      16th Mar 2005
Can someone point me in the right direction on how you can check to see if
you have an active internet connect?

Thanks,

David


 
Reply With Quote
 
 
 
 
Darren Shaffer
Guest
Posts: n/a
 
      16th Mar 2005
David - basically, you try to reach a URL and see of you get a response.
Sample method (usage: if ( CheckConnection.Once(targetURL) ) ... )

public static bool Once(string targetAddress)
{
HttpWebRequest request;
HttpWebResponse response;
bool isConnected = false;

try
{
request = (HttpWebRequest)WebRequest.Create(targetAddress);
response = (HttpWebResponse)request.GetResponse();
request.Abort();

if(response.StatusCode == HttpStatusCode.OK)
{
isConnected = true;
}
}
catch(WebException we)
{
string errMsg = we.Message;
isConnected = false;
}
catch(Exception ex)
{
string errMsg = ex.Message;
isConnected = false;
}
finally
{
request = null;
response = null;
}
return isConnected;
}

--
Darren Shaffer
Principal Architect
Connected Innovation

"David Pope" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Can someone point me in the right direction on how you can check to see if
> you have an active internet connect?
>
> Thanks,
>
> David
>



 
Reply With Quote
 
Sergey Bogdanov
Guest
Posts: n/a
 
      16th Mar 2005
You may try this:

bool IsConnected
{
get
{
int flags = 0;
return InternetGetConnectedStateEx(out flags, 0, 0, 0);
}
}

[DllImport("wininet.dll")]
private extern static bool InternetGetConnectedStateEx(out InetFlags
flags, int reservedValue, int dwNameLen, int dwReserved);

Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com


David Pope wrote:
> Can someone point me in the right direction on how you can check to see if
> you have an active internet connect?
>
> Thanks,
>
> David
>
>

 
Reply With Quote
 
Peter
Guest
Posts: n/a
 
      16th Mar 2005
Hello Sergey,

In which namespace is the InetFlags ? Cann't find it or maybe I'm
overlooking something.

Regards
Peter



"Sergey Bogdanov" <(E-Mail Removed)> schreef in bericht
news:e%(E-Mail Removed)...
> You may try this:
>
> bool IsConnected
> {
> get
> {
> int flags = 0;
> return InternetGetConnectedStateEx(out flags, 0, 0, 0);
> }
> }
>
> [DllImport("wininet.dll")]
> private extern static bool InternetGetConnectedStateEx(out InetFlags
> flags, int reservedValue, int dwNameLen, int dwReserved);
>
> Best regards,
> Sergey Bogdanov
> http://www.sergeybogdanov.com
>
>
> David Pope wrote:
> > Can someone point me in the right direction on how you can check to see

if
> > you have an active internet connect?
> >
> > Thanks,
> >
> > David
> >
> >



 
Reply With Quote
 
=?Utf-8?B?QUNQ?=
Guest
Posts: n/a
 
      16th Mar 2005
Hi

see
http://msdn.microsoft.com/library/de...tedstateex.asp


you can find it on Wininet.h

// Flags for InternetGetConnectedState and Ex
#define INTERNET_CONNECTION_MODEM 0x01
#define INTERNET_CONNECTION_LAN 0x02
#define INTERNET_CONNECTION_PROXY 0x04
#define INTERNET_CONNECTION_MODEM_BUSY 0x08 /* no longer used */
#define INTERNET_RAS_INSTALLED 0x10
#define INTERNET_CONNECTION_OFFLINE 0x20
#define INTERNET_CONNECTION_CONFIGURED 0x40


Regards

ACP


"Peter" wrote:

> Hello Sergey,
>
> In which namespace is the InetFlags ? Cann't find it or maybe I'm
> overlooking something.
>
> Regards
> Peter
>
>
>
> "Sergey Bogdanov" <(E-Mail Removed)> schreef in bericht
> news:e%(E-Mail Removed)...
> > You may try this:
> >
> > bool IsConnected
> > {
> > get
> > {
> > int flags = 0;
> > return InternetGetConnectedStateEx(out flags, 0, 0, 0);
> > }
> > }
> >
> > [DllImport("wininet.dll")]
> > private extern static bool InternetGetConnectedStateEx(out InetFlags
> > flags, int reservedValue, int dwNameLen, int dwReserved);
> >
> > Best regards,
> > Sergey Bogdanov
> > http://www.sergeybogdanov.com
> >
> >
> > David Pope wrote:
> > > Can someone point me in the right direction on how you can check to see

> if
> > > you have an active internet connect?
> > >
> > > Thanks,
> > >
> > > David
> > >
> > >

>
>
>

 
Reply With Quote
 
Sergey Bogdanov
Guest
Posts: n/a
 
      16th Mar 2005
Just replace it with 'int'.

Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com


Peter wrote:
> Hello Sergey,
>
> In which namespace is the InetFlags ? Cann't find it or maybe I'm
> overlooking something.
>
> Regards
> Peter
>
>
>
> "Sergey Bogdanov" <(E-Mail Removed)> schreef in bericht
> news:e%(E-Mail Removed)...
>
>>You may try this:
>>
>>bool IsConnected
>>{
>>get
>>{
>>int flags = 0;
>>return InternetGetConnectedStateEx(out flags, 0, 0, 0);
>>}
>>}
>>
>>[DllImport("wininet.dll")]
>>private extern static bool InternetGetConnectedStateEx(out InetFlags
>>flags, int reservedValue, int dwNameLen, int dwReserved);
>>
>>Best regards,
>>Sergey Bogdanov
>>http://www.sergeybogdanov.com
>>
>>
>>David Pope wrote:
>>
>>>Can someone point me in the right direction on how you can check to see

>
> if
>
>>>you have an active internet connect?
>>>
>>>Thanks,
>>>
>>>David
>>>
>>>

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Internet connection check via vba? Ron Microsoft Excel Programming 2 27th Aug 2007 04:40 PM
How to check for Internet connection Vikram Microsoft Excel Programming 3 16th Jun 2006 11:55 AM
Check for Internet Connection Wayne Wengert Windows XP General 1 1st Jun 2006 03:23 PM
Re: Check for Internet Connection Pegasus \(MVP\) Windows XP General 0 1st Jun 2006 03:20 PM
How can I check internet connection in vb Kadir CAMOGLU Microsoft Dot NET 1 8th Aug 2003 01:07 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:10 PM.