Real Software Forums
http://forums.realsoftware.com/

Check for internet connection (Windows OS Only)
http://forums.realsoftware.com/viewtopic.php?f=21&t=42646
Page 1 of 1

Author:  BuGs [ Sat Feb 11, 2012 2:19 pm ]
Post subject:  Check for internet connection (Windows OS Only)

1. Add the following function to a module
Function Check(aWebsite As String) As Boolean
Const FLAG_ICC_FORCE_CONNECTION = &H1
Declare Function InternetCheckConnection Lib "wininet.dll" Alias "InternetCheckConnectionA" ( lpszUrl As CString, dwFlags As Integer, dwReserved As Integer ) As Integer

If InternetCheckConnection(aWebsite, FLAG_ICC_FORCE_CONNECTION, 0) = 0 Then
Return False
Else
Return True
End If
End Function


2. Call the function anywhere in your app like this:
If Check("http://www.mdsn.com") = True Then
MsgBox "Internet Connection Available!"
Else
MsgBox "Internet Connection Not Available." + EndOfLine + "Maybe a firewall is blocking this executable?"
End If

Author:  eudosia [ Sat Feb 11, 2012 5:08 pm ]
Post subject:  Re: Check for internet connection (Windows OS Only)

Good tip! I will try It.
Thanks a lot.
Regards,
Max.

Author:  Paulemann [ Sun Feb 12, 2012 5:17 pm ]
Post subject:  Re: Check for internet connection (Windows OS Only)

Simple ping over a shell works with any OS.... much easier

Author:  amitavak [ Fri Feb 24, 2012 4:32 am ]
Post subject:  Re: Check for internet connection (Windows OS Only)

Paulemann wrote:
Simple ping over a shell works with any OS.... much easier

Can you please explain what you mean to say?

Author:  J.Hansen [ Fri Feb 24, 2012 5:07 am ]
Post subject:  Re: Check for internet connection (Windows OS Only)

Paulemann wrote:
Simple ping over a shell works with any OS.... much easier



Well ping might work for some hosts. But some companies block ping in the firewall.

Author:  amitavak [ Fri Feb 24, 2012 6:09 am ]
Post subject:  Re: Check for internet connection (Windows OS Only)

amitavak wrote:
Paulemann wrote:
Simple ping over a shell works with any OS.... much easier

Can you please explain what you mean to say?

Actually I can't understand what is "ping"? I never heard it before.

Author:  shaosean [ Fri Feb 24, 2012 11:27 am ]
Post subject:  Re: Check for internet connection (Windows OS Only)

Google is your friend http://en.wikipedia.org/wiki/Ping

Author:  charonn0 [ Fri Feb 24, 2012 9:45 pm ]
Post subject:  Re: Check for internet connection (Windows OS Only)

Some more handy functions:

Function InternetAvailable() As Boolean
//Returns True if the computer appears to have Internet access.
//Windows Vista and newer only
If System.IsFunctionAvailable("IsInternetConnected", "Connect") Then
Soft Declare Function IsInternetConnected Lib "Connect" () As Integer
Return IsInternetConnected = 0
End If
End Function


Function IsDestinationReachable(destination As String) As Boolean
//Attempts to contact the destination server. Do not include the protocol (e.g. "http://") just the server name, IP address, or UNC path.
//Windows 2000 and XP only.
If System.IsFunctionAvailable("IsDestinationReachableW", Lib "SensAPI") Then
Soft Declare Function IsDestinationReachableW Lib "Sensapi" (destination As Wstring, ByRef info As QOCINFO) As Boolean
Dim info As QOCINFO
info.sSize = info.Size
Return IsDestinationReachableW(destination, info)
End If
End Function

The QOCINFO structure for the above functionis defined as follows:
Structure QOCINFO
sSize As Integer
flags As Integer
inSpeed As Integer
outSpeed As Integer



Function NetworkAvailable() As Boolean
//Returns True if at least one network connection is alive. This does not neccessarily mean that Internet access is available.
//On error, or if no connections are alive, returns False.
//Works on Windows 2000 and newer
Declare Function IsNetworkAlive Lib "Sensapi" (ByRef netFlags As Integer) As Boolean
Declare Function GetLastError Lib "Kernel32" () As Integer
Dim flags As Integer
If IsNetWorkAlive(flags) Then
If GetLastError = 0 Then
Return True
Else
Return False
End If
Else
Return False
End If
End Function


These functions are part of a larger collection I have put together.

Author:  BuGs [ Sun Feb 26, 2012 5:34 am ]
Post subject:  Re: Check for internet connection (Windows OS Only)

Great addition charonn0

Author:  amitavak [ Thu Jul 12, 2012 6:02 am ]
Post subject:  Re: Check for internet connection (Windows OS Only)

Hi charonn0,

Your functions are working great on windows.

But I need a platform independent solution. Do you have any suggestion?

Thanks

Author:  charonn0 [ Thu Jul 12, 2012 11:38 am ]
Post subject:  Re: Check for internet connection (Windows OS Only)

Sorry, nope. Windows is my bailiwick.

Author:  DaveS [ Thu Jul 12, 2012 11:41 am ]
Post subject:  Re: Check for internet connection (Windows OS Only)

PING is platform independant... . OSX and Windows both include a PING utility...

And if all you are looking for is Internet Connectivity.... just PING GOOGLE...

Not going to give you all the code..... but use SHELL and look up ping on Google if you don't know what it is...


(not sure how anyone can have done any kind of internet/network stuff and still not know PING... but ok)

Author:  fishmonger [ Sun Jul 29, 2012 10:53 am ]
Post subject:  Re: Check for internet connection (Windows OS Only)

I'm joining this thread a little late, but here's my $.02

I'd use ping as has already been suggested, but instead of pinging google or any other url, I'd ping at least 1 if not 2 different root (DNS) servers by IP address (https://www.iana.org/domains/root/servers).

Why? Because your internet connection could be up but google could be down and as such not responding to pings. Or, your dns could be down and unable resolve the IP that needs to be ping'd.

If you really want/need to, you could then take the next step and test DNS resolution.

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/