Google Answers Logo
View Question
 
Q: Using vb to find out if the computer is on the internet ( Answered,   2 Comments )
Question  
Subject: Using vb to find out if the computer is on the internet
Category: Computers
Asked by: faith16-ga
List Price: $5.00
Posted: 07 Apr 2003 09:21 PDT
Expires: 07 May 2003 09:21 PDT
Question ID: 187186
Using vb7 how do you find out if the computer is on the internet?

Clarification of Question by faith16-ga on 07 Apr 2003 13:31 PDT
Hi, i tried the api mentioned in the topic but haven't managed to get this to work
Answer  
Subject: Re: Using vb to find out if the computer is on the internet
Answered By: theta-ga on 08 Apr 2003 01:51 PDT
 
Hi faith16-ga,
    Finding out the status of the computer's network connection status
is a fairly popular need with developers, and you'd think that there
would be a method in .NET to provide this information. Unfortunately,
.NET contains no in built method to detect and provide this
information. So, here are some tricks developers use to find out the
computers connection status:
- [1] Ping a valid IP address.
   This appears to be the most foolproof method of checking the
connection status. Be sure to use a valid IP address (say
216.239.33.99) insted of a domain name (say www.google.com), since
using a domain name will cause the computer to start dialling the
network service provider if the computer is not connected. It will
also cause problems with dial-up internet connection sharing (the
"server" system will dial whenever one of the client systems does any
of these types of calls). And you don't want that, since it will
irritate your users no end.
  There are a couple of methods you can use to ping an IP address:
       - Use the WMI(Windows Management Instrumentation)
Win32_PingStatus class
         As specified in the below mentioned ExpertsExchange question,
this require only two lines of code. Here is the code...
     =============================
      dim x as new system.management.managementobject("Win32_PingStatus.Address='65.5.21.23'")
      msgbox x.properties("StatusCode").Value.ToString
     ============================= 
         as given on this page:
             - ExpertsExchange: pinging an IP using .NET framework
classes
               (http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/Q_20394521.html)
        For more information on the Win32_PingStatus WMI class and its
return values, see the following MSDN Library article:
             - MSDN : Platform SDK: WMI > Win32_PingStatus
               (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_pingstatus.asp)
       
       -  Another way to ping an IP address is by using the System.Net
classes. You can find example code in the following newsgroup threads:
             - Subject: Ping in VB.net
               Newsgroup: microsoft.public.dotnet.languages.vb
               (http://groups.google.com/groups?threadm=rwZt9.86018%24zE6.289161%40rwcrnsc51.ops.asp.att.net)
             - Subject: Can anyone convert this C# sample to VB.NET?
               Newsgroup: microsoft.public.dotnet.languages.vb
               (http://groups.google.com/groups?threadm=eNav9.143113%24%25d2.51429%40sccrnsc01)


- [2] Use the InternetGetConnectedState() Win32 API function (also
suggested by hammer-ga in his comment)
  Unfortunately, the InternetGetConnectedState() API(available with IE
4 and above) is not entirely reliable. It's exact functioning varies
with the version of IE installed, and in certain cases, it may be
unable to detect an internet connection, even when the computer is
online.
  For more information, please check out the following articles:
      - MSKB Article 315035: The InternetGetConnectedState Function
Returns FALSE When Connected to the Internet
        (http://support.microsoft.com/?kbid=315035)
      - MSKB Article 242558: Detecting If You Have a Connection to the
Internet
        (http://support.microsoft.com/?kbid=242558)
      - InternetGetConnectedState Event Handler
        (http://66.129.67.100/247reference/msgs/5/28316.aspx)


- [3] Try connecting to a website/webpage (as also suggested by
sgtcory-ga in his comment)
  This method unfortunately suffers from the dialling problem that I
mention while discussing the ping method. Every time you try to check
your online status this way, it will cause the host computer to dial
if it is not online.
  See the following newsgroup thread:
     - Subject: How to detect internet connection?
       Newsgroup: microsoft.public.dotnet.framework.windowsforms
       (http://groups.google.com/groups?threadm=%23GWCO0xvBHA.2660%40tkmsftngp05)


- [4] Check the computer's local IP address. If this address is the
loopback address (127.0.0.1) then the machine is not connected to a
network. Please see the following newsgroup post for the required
VB.NET code:
       - Subject: Internet connection detect 
         Newsgroups: microsoft.public.dotnet.languages.vb
         (http://groups.google.com/groups?selm=Odvz4%23TeCHA.1876%40tkmsftngp10)
      Unfortunately, this method is also not foolproof. It will give
you an incorrect result if the user is on a network without being
connected to the Internet.

-------------------------------------------

Hope this helps.

If you need any clarifications, just ask!

Regards,
Theta-ga
:-)



===========================================
Google/Google Groups Search Terms Used:
  detect internet connection
  InternetGetConnectedState
  using ping to detect internet connection
Comments  
Subject: Re: Using vb to find out if the computer is on the internet
From: hammer-ga on 07 Apr 2003 10:43 PDT
 
You can use the InternetGetConnectedState API that is installed with
IE4 and higher. A full module that you can cut-and-paste is available
at mvps.org.

MVPS VB.Net FAQ
http://www.mvps.org/vbnet/index.html?code/network/internetgetconnectedstate.htm

Also see the Related links on this page for several other methods of
testing various network states.

I have not posted this as an answer, because I don't have a .Net test
environment available and the code is marked for VB6. I believe it
will also work with .Net.

- Hammer
Subject: Re: Using vb to find out if the computer is on the internet
From: sgtcory-ga on 07 Apr 2003 18:43 PDT
 
Not even sure if you are developing in this capacity, but this may be
an alternative :

.Net247
http://www.dotnet247.com/247reference/msgs/8/43560.aspx

I'll keep looking for you, but much like hammer, I don't have a .NET
test environment.

SgtCory

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy