Connected to the net?

I searched alot for an answer to this question but no luck.
I want to know if I am connected to the internet or not, I may be connected from another computer (lan).

Some of the answer they gave me:
-Ping website
its not good since my program is going to check for internet connection every sec, and using batch wont be good then
-API --> GetConnectionStat / InternetConnectionEx / IsConnected
all these are telling me that I am connected to the net when I am only connected to the network

I got many other answers but the codes wount be able to tell me that I am connected to the net when I am recieving connection from another PC
can u help?
thx
instant_newAsked:
Who is Participating?
 
dbrckoviConnect With a Mentor Commented:
Try creating a new Web Browser form. Set its MDIChild property to False.
On Form1 create one command button and one timer.
Paste this code:
------------------------------------
Private Sub Command1_Click()
    frmBrowser.cboAddress.Clear
    frmBrowser.cboAddress.AddItem "www.google.com"
    frmBrowser.cboAddress.ListIndex = 0
   
    Timer1.Interval = 1000
    Timer1.Tag = 1
    Timer1.Enabled = True
End Sub

Private Sub Form_Load()
    Load frmBrowser
    frmBrowser.Hide
End Sub

Private Sub Timer1_Timer()
    Timer1.Tag = Timer1.Tag + 1
    If Timer1.Tag = 60 Then
        Form1.Caption = "Not connected ... try again later"
        Timer1.Enabled = False
        Exit Sub
    End If
   
   
    Form1.Caption = "Waiting..."
    If frmBrowser.Caption = "Google" Then
        Form1.Caption = "Connected"
        Timer1.Enabled = False
    End If
End Sub
-----------------------------------------
Each time you click a button, request for openning google page will be sent.
Timer will then check every second if frmBrowsers caption was changed.
If it doesn't change to "Google" in 60 seconds, then you are probably not connected.   ( I think 60 sec should be more than enough to load google )
0
 
instant_newAuthor Commented:
@dbrckovi
well that worked, but there must be a better way, without using a Web Browser Form...
I'll wait for new replies if not u will get points

@EDDYKT
it is always saying Reachable >> No
it isnt working, although it would be great if it worked.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
EDDYKTConnect With a Mentor Commented:
Try this

Option Explicit

Const NETWORK_ALIVE_AOL = &H4
Const NETWORK_ALIVE_LAN = &H1
Const NETWORK_ALIVE_WAN = &H2
Private Type QOCINFO
    dwSize As Long
    dwFlags As Long
    dwInSpeed As Long 'in bytes/second
    dwOutSpeed As Long 'in bytes/second
End Type
Private Declare Function IsDestinationReachable Lib "SENSAPI.DLL" Alias "IsDestinationReachableA" (ByVal lpszDestination As String, ByRef lpQOCInfo As QOCINFO) As Long
Private Sub Form_Load()
    'KPD-Team 2001
    'URL: http://www.allapi.net/
    'E-Mail: KPDTeam@Allapi.net
    Dim Ret As QOCINFO
    Ret.dwSize = Len(Ret)
    If IsDestinationReachable("www.allapi.net", Ret) = 0 Then
        MsgBox "The destination cannot be reached!"
    Else
        MsgBox "The destination can be reached!" + vbCrLf + _
           "The speed of data coming in from the destination is " + Format$(Ret.dwInSpeed / 1024, "#.0") + " Kb/s," + vbCrLf + _
           "and the speed of data sent to the destination is " + Format$(Ret.dwOutSpeed / 1024, "#.0") + " Kb/s."
    End If
End Sub
 


From http://www.mentalis.org/apilist/IsDestinationReachable.shtml
0
 
dbrckoviCommented:
I agree that there must be a better way.
Take my example just as a backup sollution if nothing else works.
In the meanwhile, I would suggest you to stick with EDDYKT. He might be on the right track.

0
 
leonstrykerCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Split dbrckovi, EDDYKT
 
Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

leonstryker
EE Cleanup Volunteer
0
 
dbrckoviCommented:
Thanks.
0
All Courses

From novice to tech pro — start learning today.