?
Solved

How can my application detect if i am connected to the internet, and what method i use to connect.(Modem or LAN) ?

Posted on 2003-03-01
13
Medium Priority
?
157 Views
Last Modified: 2010-04-07
Dear experts,Hi.
I need a VB program that is able to detedct if i am connected to the internet or not and by Modem or LAN ?(IMMEDIATELY)
I 've searched lots of sites for that and found lots of codes for that . All of the codes owners have claimed their codes work well. but i 've tested all of them and each has some problems .
for example those ones that have used wininet, if you are not connected to the internet tells  that you are connected to the internet via LAN.
I dont want to use pinging method .

 
0
Comment
Question by:rosalinda
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
13 Comments
 
LVL 4

Expert Comment

by:mcoop
ID: 8051083
how about pinging a known reliable (external) address...
the result is the result
0
 
LVL 1

Expert Comment

by:Belfry
ID: 8051123
but why don't you use InetIsOffline?
returns true if offline or not yet made a connect attempt, false if connected.
0
 

Author Comment

by:rosalinda
ID: 8051361
Dear mcoop
when i am disconnected,pinging causes to appear dialup connection dialogbox and i don't want that.
do you have any solution for this problem?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:rosalinda
ID: 8051369
Dear Belfry ,
Can you give me more details about using InetIsOffline?
How can i use it in my code?Please write for me.
0
 

Author Comment

by:rosalinda
ID: 8051381
Dear Belfry ,
Can you give me more details about using InetIsOffline?
How can i use it in my code?Please write for me.
0
 
LVL 28

Expert Comment

by:vinnyd79
ID: 8051658
0
 
LVL 1

Expert Comment

by:Belfry
ID: 8051801
Ok, first declare it

'assume it's declared in a form
Private Declare Function InetIsOffline Lib "url.dll" (ByVal dwFlags As Long) As Long

then use it somewhere, e.g:

Private Sub Form_Load()
dim bIsOnLine as Boolean
bIsOnLine=Not InetIsOffline()
if bIsOnLine then
 'tell the user that he's currently online
else
 'tell the user that he's not yet connected to the internet
end if
End Sub

:)
0
 
LVL 1

Expert Comment

by:Belfry
ID: 8054251
oops, sorry, i missed a paramter for InetIsOffline
...
Dim bIsOnLine as Boolean
bIsOnLine=Not InetIsOffline(0)'the parameter must be 0
...
0
 

Author Comment

by:rosalinda
ID: 8055344
Dear Belfry ,
I don't know why but It always says "you are online".
0
 
LVL 1

Expert Comment

by:FunkyMeister
ID: 8200650
Two functions from my Internet Module (not done with it, why you can't download it yet).

Declares:

Private Declare Function InternetAttemptConnect Lib "wininet.dll" (ByVal dwReserved As Long) As Long
Private Declare Function InternetGetConnectedStateEx Lib "wininet.dll" Alias "InternetGetConnectedStateExA" (ByRef lpdwFlags As Long, ByVal lpszConnectionName As String, ByVal dwNameLen As Long, ByVal dwReserved As Long) As Long
Private Const INTERNET_CONNECTION_MODEM = &H1&
Private Const INTERNET_CONNECTION_LAN = &H2&
Private Const INTERNET_CONNECTION_PROXY = &H4&
Private Const INTERNET_RAS_INSTALLED = &H10&
Private Const INTERNET_CONNECTION_OFFLINE = &H20&
Private Const INTERNET_CONNECTION_CONFIGURED = &H40&


Functions:


Public Function canAttempt() As Boolean
canAttempt = IIf(InternetAttemptConnect(ByVal 0&) = 0, True, False)
End Function

Public Function Connection() As Boolean
   Dim dwFlags As Long
   Dim sNameBuf As String, msg As String
   Dim lPos As Long
   sNameBuf = String$(513, 0)
   If (InternetGetConnectedStateEx(dwFlags, sNameBuf, 512, 0&)) Then
      'Yes, you have active connection
      'Collect ExtraInfo:
      'lPos = InStr(sNameBuf, vbNullChar)
      'If lPos > 0 Then sConnectionName = Left$(sNameBuf, lPos - 1)
      'ConnectionInfo = dwFlags
      'Now ConnectionInfo variable contain OR'ed INTERNET_ flags (see constants above)
      'You can extract info you need with And keyford:
      If (dwFlags And INTERNET_CONNECTION_LAN) Then
       Connection = True
       'MsgBox "Your connection use LAN"
      ElseIf (dwFlags And INTERNET_CONNECTION_MODEM) Then
       Connection = True
       'MsgBox "Your connection use Modem"
      End If
   Else
      Connection = False
      'MsgBox = "Your computer is NOT connected to Internet"
   End If
End Function

Downside of this code, Network (lan) users can always connect.

The Connection() returns whether or not it CAN connect.

The canAttempt() returns whether or not it is able to connect (login to the internet), this is useful for modem users so you can tell IF they've denied dialing.

Best first to see if you CAN connect with the canAttempt() function and if you can, see if you ARE connected with the Connection() function (WILL return true IF a modem user has a default dialup and has enabled dial on demand).

Should be enough to help.
0
 

Expert Comment

by:CleanupPing
ID: 8900918
rosalinda:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 9012019
rosalinda, an EE Moderator will handle this for you.
Moderator, my recommended disposition is:

    Save as PAQ -- No Refund.

DanRollins -- EE database cleanup volunteer
0
 

Accepted Solution

by:
PashaMod earned 0 total points
ID: 9146384
Per recommendation

PashaMod
CS Moderator
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month9 days, 11 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question