Jump to content
Sign in to follow this  

Best Way To Test Internet Connection

Recommended Posts


I'm trying to put in a way to check internet in my script I'm working on.

Someone said I should use the TestConnection() function, and I have it in the script but it's not working as it should

I want the script to for instance, if the user has internet, let the user know via an msg box that internet is available and continue with the rest of the script. Otherwise, if internet is not available, tell them with a msg box that no internet is detected and exit.

The function should ping google to test net connectivity. This is what I have, it fails, though:

ToolTip("Checking Internet", 0, 0, "Checking for internet connectivity.", 0)
While $AmIConnectedYet = 1
MsgBox(0, "Connection Detected", "An internet connection has been detected, continuing on ...", 2)
While $AmIConnectedYet = 0
MsgBox(0, "No Connection Detected", "An internet connection was not detected, Exiting ...", 2)
Func TestConnection()
While $AmIConnectedYet <> "True"
$ping = Ping("google.com")
If $ping > 0 then
    $AmIConnectedYet = "True"
Edited by rayven

Share this post

Link to post
Share on other sites

Use this function it's really good i use it too.

Edited by Aipion

Share this post

Link to post
Share on other sites

Here's a canny way from guinness that i always use

$net_test = _IsInternetConnectedEx()
If $net_test = 1 Then
$net_test = "Connected"
$net_test = "Not Connected"
ConsoleWrite("Internet Is " & $net_test & @CRLF)

Func _IsInternetConnectedEx() ; Returns 1 = ON or 0 = OFF
    Local $is_Return = DllCall("wininet.dll", "int", "InternetGetConnectedState", "int", 0, "int", 0)
    If (@error) Or ($is_Return[0] = 0) Then Return SetError(1, 0, 0)
    Return 1
EndFunc   ;==>_IsInternetConnectedEx

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this