Home All Groups Group Topic Archive Search About

Internet connectivity

Author
9 May 2006 10:40 PM
Adam Honek
Hi all,

How would one test for internet connectivity in VB.NET instead
of using the Win32 API methods?

Thanks,
Adam

Author
10 May 2006 12:25 AM
tomb
WebRequest

T

Adam Honek wrote:

Show quoteHide quote
>Hi all,
>
>How would one test for internet connectivity in VB.NET instead
>of using the Win32 API methods?
>
>Thanks,
>Adam
>
>

>
Author
10 May 2006 1:01 AM
Adam Honek
What namespace is this?

..net??

Adam

Show quoteHide quote
"tomb" <t***@technetcenter.com> wrote in message
news:bsa8g.39801$MM6.38564@bignews3.bellsouth.net...
> WebRequest
>
> T
>
> Adam Honek wrote:
>
>>Hi all,
>>
>>How would one test for internet connectivity in VB.NET instead
>>of using the Win32 API methods?
>>
>>Thanks,
>>Adam
>>
>>
Author
10 May 2006 6:35 PM
tomb
Yes.

T

Adam Honek wrote:

Show quoteHide quote
>What namespace is this?
>
>.net??
>
>Adam
>
>"tomb" <t***@technetcenter.com> wrote in message
>news:bsa8g.39801$MM6.38564@bignews3.bellsouth.net...

>
>>WebRequest
>>
>>T
>>
>>Adam Honek wrote:
>>
>>   
>>
>>>Hi all,
>>>
>>>How would one test for internet connectivity in VB.NET instead
>>>of using the Win32 API methods?
>>>
>>>Thanks,
>>>Adam
>>>
>>>
>>>     
>>>
>
>

>
Author
10 May 2006 4:43 AM
Cor Ligthert [MVP]
Adam,

Pinging the first IP address outside your own environment is the way as is
always used with or withouth a program.

Cor

Show quoteHide quote
"Adam Honek" <AdamHo***@Webmaster2001.freeserve.co.uk> schreef in bericht
news:eKyZRm7cGHA.4224@TK2MSFTNGP04.phx.gbl...
> Hi all,
>
> How would one test for internet connectivity in VB.NET instead
> of using the Win32 API methods?
>
> Thanks,
> Adam
>
Author
10 May 2006 4:51 AM
Adam Honek
Yes I realise it's done via ICMP but I thought .NET has its own method
to check it without employing specialised techniques.

Adam

Show quoteHide quote
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
news:uL$4Cw%23cGHA.3632@TK2MSFTNGP05.phx.gbl...
> Adam,
>
> Pinging the first IP address outside your own environment is the way as is
> always used with or withouth a program.
>
> Cor
>
> "Adam Honek" <AdamHo***@Webmaster2001.freeserve.co.uk> schreef in bericht
> news:eKyZRm7cGHA.4224@TK2MSFTNGP04.phx.gbl...
>> Hi all,
>>
>> How would one test for internet connectivity in VB.NET instead
>> of using the Win32 API methods?
>>
>> Thanks,
>> Adam
>>
>
>
Author
10 May 2006 5:09 AM
gene kelley
On Tue, 9 May 2006 23:40:26 +0100, "Adam Honek"
<AdamHo***@Webmaster2001.freeserve.co.uk> wrote:

>Hi all,
>
>How would one test for internet connectivity in VB.NET instead
>of using the Win32 API methods?
>
>Thanks,
>Adam
>

If you want to know if a user is able to connect to the internet:
     Dim isAvailable As Boolean
        isAvailable = My.Computer.Network.IsAvailable

False = user has no current network connection of any kind
True = user is connected to a network of some sort, but doesn't
necessarily mean the internet is reachable.

The companion statement to the above is:
My.Computer.Network.NetworkAvailabilityChanged

I usually do the above at startup in (MyApplicationEvents).

Whether or not you use the above, each attempt to reach a server
should use WebRequest and a Try/Catch Block where you are looking for
a response of "OK" (200).  If there is a problem, you would interpret
the exception message which could be "No Connection", "Not
Authorized", "Timeout" etc.

There are WebRequest examples in the help file if you need them.

Gene
Author
10 May 2006 7:30 AM
Adam Honek
I've done what you suggest with WebRequest  but it seems it's quite
a thread hog if it's called every second. Unless I put it in its own thread
the UI thread is visibly interupted.

Hmmm, maybe instead of pinging a website it pinged the NIC default IP
gateway on one's PC, this would give better performance?

Nice method though, quick and easy.

Adam


Show quoteHide quote
"gene kelley" <o***@by.me> wrote in message
news:vup262lfu6mcil36t5f605pvo3ptksdv8h@4ax.com...
> On Tue, 9 May 2006 23:40:26 +0100, "Adam Honek"
> <AdamHo***@Webmaster2001.freeserve.co.uk> wrote:
>
>>Hi all,
>>
>>How would one test for internet connectivity in VB.NET instead
>>of using the Win32 API methods?
>>
>>Thanks,
>>Adam
>>
>
> If you want to know if a user is able to connect to the internet:
>     Dim isAvailable As Boolean
>        isAvailable = My.Computer.Network.IsAvailable
>
> False = user has no current network connection of any kind
> True = user is connected to a network of some sort, but doesn't
> necessarily mean the internet is reachable.
>
> The companion statement to the above is:
> My.Computer.Network.NetworkAvailabilityChanged
>
> I usually do the above at startup in (MyApplicationEvents).
>
> Whether or not you use the above, each attempt to reach a server
> should use WebRequest and a Try/Catch Block where you are looking for
> a response of "OK" (200).  If there is a problem, you would interpret
> the exception message which could be "No Connection", "Not
> Authorized", "Timeout" etc.
>
> There are WebRequest examples in the help file if you need them.
>
> Gene
Author
10 May 2006 9:06 AM
Andrew Morton
Adam Honek wrote:
> Hmmm, maybe instead of pinging a website it pinged the NIC default IP
> gateway on one's PC, this would give better performance?

The default gateway is not necessarily outside the LAN. Neither is(are) the
DNS Server(s).

E.g. C:\>ipconfig

Windows IP Configuration

Ethernet adapter Local Area Connection:

   IP Address. . . . . . . . . . . . : 192.168.123.14
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 192.168.123.1 <-firewall appliance

Andrew
Author
10 May 2006 9:23 AM
gene kelley
On Wed, 10 May 2006 08:30:38 +0100, "Adam Honek"
<AdamHo***@Webmaster2001.freeserve.co.uk> wrote:

>I've done what you suggest with WebRequest  but it seems it's quite
>a thread hog if it's called every second. Unless I put it in its own thread
>the UI thread is visibly interupted.
>
>Hmmm, maybe instead of pinging a website it pinged the NIC default IP
>gateway on one's PC, this would give better performance?
>
>Nice method though, quick and easy.
>
>Adam
>
>

I'm not sure what you mean by "called every second".  Here is a snip
of something I use.  When the execution gets to this point, it's
either a valid response, or there was an exception.  On a broadband
connection, here, from the time the URL is selected until  the picture
is completely displayed is generally 2-3 seconds.  Exceptions other
than timeout are virtually instaneous. 

(Code is used in a BackgroundWorker component, DoWork event)

       Try
            Dim request As HttpWebRequest =
DirectCast(WebRequest.Create(PicLoc), HttpWebRequest)
            request.Timeout = 10000
            Dim response As HttpWebResponse =
DirectCast(request.GetResponse(), HttpWebResponse)
            If response.StatusDescription = "OK" Then
                 RequestStatus = True
            End If
            response.Close()

        Catch ex As WebException

            Select Case ex.Status
                Case WebExceptionStatus.ConnectFailure

       Case WebExceptionStatus.Timeout

       Case WebExceptionStatus.ProtocolError

      Case Else

    end select

    End Try


Gene
Author
10 May 2006 9:46 AM
Adam Honek
Yup so yours is not running in the same time slice as the UI is. On mine
it's currently running this way hence there's this lag in moving the window
or even clicking through the menus.

That above is why I have a threading question posted in this newsgroup.

Thanks,
Adam

Show quoteHide quote
"gene kelley" <o***@by.me> wrote in message
news:rda362ls7tm7bq5pktg7kremf1gaghodjo@4ax.com...
> On Wed, 10 May 2006 08:30:38 +0100, "Adam Honek"
> <AdamHo***@Webmaster2001.freeserve.co.uk> wrote:
>
>>I've done what you suggest with WebRequest  but it seems it's quite
>>a thread hog if it's called every second. Unless I put it in its own
>>thread
>>the UI thread is visibly interupted.
>>
>>Hmmm, maybe instead of pinging a website it pinged the NIC default IP
>>gateway on one's PC, this would give better performance?
>>
>>Nice method though, quick and easy.
>>
>>Adam
>>
>>
>
> I'm not sure what you mean by "called every second".  Here is a snip
> of something I use.  When the execution gets to this point, it's
> either a valid response, or there was an exception.  On a broadband
> connection, here, from the time the URL is selected until  the picture
> is completely displayed is generally 2-3 seconds.  Exceptions other
> than timeout are virtually instaneous.
>
> (Code is used in a BackgroundWorker component, DoWork event)
>
>       Try
>            Dim request As HttpWebRequest =
> DirectCast(WebRequest.Create(PicLoc), HttpWebRequest)
>            request.Timeout = 10000
>            Dim response As HttpWebResponse =
> DirectCast(request.GetResponse(), HttpWebResponse)
>            If response.StatusDescription = "OK" Then
>                 RequestStatus = True
>            End If
>            response.Close()
>
>        Catch ex As WebException
>
>            Select Case ex.Status
>                Case WebExceptionStatus.ConnectFailure
>
>    Case WebExceptionStatus.Timeout
>
>    Case WebExceptionStatus.ProtocolError
>
>   Case Else
>
> end select
>
>    End Try
>
>
> Gene