|
-
Aug 16th, 2003, 09:48 AM
#1
Thread Starter
Need-a-life Member
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.
-
Aug 16th, 2003, 11:11 AM
#2
Hyperactive Member
probaly not the correct way... but you could ping google
-
Aug 16th, 2003, 11:43 AM
#3
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:
Option Explicit
Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" ( _
ByVal sAgent As String, _
ByVal lAccessType As Long, _
ByVal sProxyName As String, _
ByVal sProxyBypass As String, _
ByVal lFlags As Long) As Long
Private Declare Function InternetConnect Lib "wininet.dll" Alias "InternetConnectA" ( _
ByVal hInternetSession As Long, _
ByVal sServerName As String, _
ByVal nServerPort As Integer, _
ByVal sUsername As String, _
ByVal sPassword As String, _
ByVal lService As Long, _
ByVal lFlags As Long, _
ByVal lContext As Long) As Long
Private Declare Function HttpOpenRequest Lib "wininet.dll" Alias "HttpOpenRequestA" ( _
ByVal hHttpSession As Long, _
ByVal sVerb As String, _
ByVal sObjectName As String, _
ByVal sVersion As String, _
ByVal sReferer As String, _
ByVal something As Long, _
ByVal lFlags As Long, _
ByVal lContext As Long) As Long
Private Declare Function HttpSendRequest Lib "wininet.dll" Alias "HttpSendRequestA" ( _
ByVal hHttpRequest As Long, _
ByVal sHeaders As String, _
ByVal lHeadersLength As Long, _
ByVal sOptional As String, _
ByVal lOptionalLength As Long) As Long
Private Declare Function InternetCloseHandle Lib "wininet.dll" ( _
ByVal hInet As Long) As Integer
Private Const INTERNET_FLAG_RELOAD = &H80000000
Private Const INTERNET_SERVICE_HTTP = 3
Private Const INTERNET_OPEN_TYPE_PRECONFIG = 0
Public Function IsInternetReady() As Boolean
Dim lSession As Long
Dim lConnect As Long
Dim lRequest As Long
Dim lResponse As Long
Const sURL = "www.microsoft.com"
' Open an Internet Session
lSession = InternetOpen("NetReady", _
INTERNET_OPEN_TYPE_PRECONFIG, _
vbNullString, _
vbNullString, _
0)
If lSession = 0 Then Exit Function
' Create a connection
lConnect = InternetConnect(lSession, _
sURL, _
80, _
vbNullString, _
vbNullString, _
INTERNET_SERVICE_HTTP, _
0, _
0)
' Generate an HTTP GET request
lRequest = HttpOpenRequest(lConnect, _
"GET", _
sURL, _
"HTTP/1.0", _
vbNullString, _
0, _
INTERNET_FLAG_RELOAD, _
0)
' Send the request, Response will be non-zero if successful
lResponse = HttpSendRequest(lRequest, _
vbNullString, _
Len(vbNullString), _
vbNullString, _
Len(vbNullString))
Call InternetCloseHandle(lSession)
Call InternetCloseHandle(lConnect)
Call InternetCloseHandle(lRequest)
IsInternetReady = lResponse
End Function
-
Aug 16th, 2003, 11:50 AM
#4
Thread Starter
Need-a-life Member
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.
-
Aug 16th, 2003, 04:30 PM
#5
Frenzied Member
Just to add on to what you might already have:
VB Code:
Private Declare Function InetIsOffline Lib "url.dll" (ByVal dwFlags As Long) As Long
Private Sub Form_Load()
'KPD-Team 2001
'URL: [url]http://www.allapi.net/[/url]
'InetIsOffline returns 0 if you're connected
MsgBox "Are you connected to the internet? " + CStr(CBool(Not (InetIsOffline(0)))), vbInformation
End Sub
-
Sep 9th, 2003, 12:11 PM
#6
Member
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.
-
May 23rd, 2004, 10:29 PM
#7
Fanatic Member
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
-
May 31st, 2004, 10:53 AM
#8
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|