Results 1 to 8 of 8

Thread: Detecting Internet Connection - Cablemodem

  1. #1

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808

    Detecting Internet Connection - Cablemodem

    Does anybody have a working code to know if we have access to Internet or not through Cablemodem?
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  2. #2
    Hyperactive Member BrandonTurner's Avatar
    Join Date
    Sep 2001
    Location
    East Lansing, Michiagn
    Posts
    268
    probaly not the correct way... but you could ping google

  3. #3
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177
    Sending a request to a remote node is really the only reliable
    way to know whether you're connected to the internet or not.

    Anything else will just check to see if you're on a network.

    So you can do as Brandon suggested and ping a URL you know is
    likely to be up when connected to the internet, better yet, have a
    list of 2 or 3 URL's.

    Example:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" ( _
    4.   ByVal sAgent As String, _
    5.   ByVal lAccessType As Long, _
    6.   ByVal sProxyName As String, _
    7.   ByVal sProxyBypass As String, _
    8.   ByVal lFlags As Long) As Long
    9.  
    10. Private Declare Function InternetConnect Lib "wininet.dll" Alias "InternetConnectA" ( _
    11.   ByVal hInternetSession As Long, _
    12.   ByVal sServerName As String, _
    13.   ByVal nServerPort As Integer, _
    14.   ByVal sUsername As String, _
    15.   ByVal sPassword As String, _
    16.   ByVal lService As Long, _
    17.   ByVal lFlags As Long, _
    18.   ByVal lContext As Long) As Long
    19.  
    20. Private Declare Function HttpOpenRequest Lib "wininet.dll" Alias "HttpOpenRequestA" ( _
    21.   ByVal hHttpSession As Long, _
    22.   ByVal sVerb As String, _
    23.   ByVal sObjectName As String, _
    24.   ByVal sVersion As String, _
    25.   ByVal sReferer As String, _
    26.   ByVal something As Long, _
    27.   ByVal lFlags As Long, _
    28.   ByVal lContext As Long) As Long
    29.  
    30. Private Declare Function HttpSendRequest Lib "wininet.dll" Alias "HttpSendRequestA" ( _
    31.   ByVal hHttpRequest As Long, _
    32.   ByVal sHeaders As String, _
    33.   ByVal lHeadersLength As Long, _
    34.   ByVal sOptional As String, _
    35.   ByVal lOptionalLength As Long) As Long
    36.  
    37. Private Declare Function InternetCloseHandle Lib "wininet.dll" ( _
    38.   ByVal hInet As Long) As Integer
    39.  
    40. Private Const INTERNET_FLAG_RELOAD = &H80000000
    41. Private Const INTERNET_SERVICE_HTTP = 3
    42. Private Const INTERNET_OPEN_TYPE_PRECONFIG = 0
    43.  
    44. Public Function IsInternetReady() As Boolean
    45.   Dim lSession As Long
    46.   Dim lConnect As Long
    47.   Dim lRequest As Long
    48.   Dim lResponse As Long
    49.  
    50.   Const sURL = "www.microsoft.com"
    51.  
    52.   ' Open an Internet Session
    53.   lSession = InternetOpen("NetReady", _
    54.                           INTERNET_OPEN_TYPE_PRECONFIG, _
    55.                           vbNullString, _
    56.                           vbNullString, _
    57.                           0)
    58.                          
    59.   If lSession = 0 Then Exit Function
    60.  
    61.   ' Create a connection
    62.   lConnect = InternetConnect(lSession, _
    63.                              sURL, _
    64.                              80, _
    65.                              vbNullString, _
    66.                              vbNullString, _
    67.                              INTERNET_SERVICE_HTTP, _
    68.                              0, _
    69.                              0)
    70.  
    71.   ' Generate an HTTP GET request
    72.   lRequest = HttpOpenRequest(lConnect, _
    73.                              "GET", _
    74.                              sURL, _
    75.                              "HTTP/1.0", _
    76.                              vbNullString, _
    77.                              0, _
    78.                              INTERNET_FLAG_RELOAD, _
    79.                              0)
    80.                                
    81.   ' Send the request, Response will be non-zero if successful
    82.   lResponse = HttpSendRequest(lRequest, _
    83.                               vbNullString, _
    84.                               Len(vbNullString), _
    85.                               vbNullString, _
    86.                               Len(vbNullString))
    87.  
    88.   Call InternetCloseHandle(lSession)
    89.   Call InternetCloseHandle(lConnect)
    90.   Call InternetCloseHandle(lRequest)
    91.  
    92.   IsInternetReady = lResponse
    93. End Function

  4. #4

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Thanks, Aaron. It worked!!
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  5. #5
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    Just to add on to what you might already have:

    VB Code:
    1. Private Declare Function InetIsOffline Lib "url.dll" (ByVal dwFlags As Long) As Long
    2. Private Sub Form_Load()
    3.     'KPD-Team 2001
    4.     'URL: [url]http://www.allapi.net/[/url]
    5.     'E-Mail: [email][email protected][/email]
    6.     'InetIsOffline returns 0 if you're connected
    7.     MsgBox "Are you connected to the internet? " + CStr(CBool(Not (InetIsOffline(0)))), vbInformation
    8. End Sub
    Please rate my post.

  6. #6
    Member
    Join Date
    Jan 1999
    Location
    Warner Robins, GA
    Posts
    37
    Pinging to detect an internet connection may not work in some cases if your ISP has disabled that capability. Due to some of the virus attacks of late, I know someone whose ISP disabled the ping capabilities.

  7. #7
    Fanatic Member SkiNLaB's Avatar
    Join Date
    Jan 2002
    Location
    Sydney, Australia
    Posts
    747
    Just to clairfy, Aaron young's solution doesn't ping does it... it uses HTTP to verify the connection... yeah?

    Either way, I'm using it, thanks I think I'll use two sites, google and microsoft

  8. #8
    Fanatic Member ZeBula8's Avatar
    Join Date
    Oct 2002
    Posts
    548

    is something being cached here...?

    I can use Aaron's code with great success but only on the first time. If I then remove the network connection and test it again, it returns a success value that I am connected to the Internet when in fact I am not.

    Is this checking something that is cached?

    If this is the case - is there a way to clear the cache before running a check for connectivity?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width