Jump to content

Best Way To Test Internet Connection


rayven
 Share

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)
TestConnection()
While $AmIConnectedYet = 1
MsgBox(0, "Connection Detected", "An internet connection has been detected, continuing on ...", 2)
Wend
While $AmIConnectedYet = 0
MsgBox(0, "No Connection Detected", "An internet connection was not detected, Exiting ...", 2)
exit;
Wend
Func TestConnection()
While $AmIConnectedYet <> "True"
$ping = Ping("google.com")
If $ping > 0 then
    $AmIConnectedYet = "True"
EndIf
WEnd
EndFunc
Edited by rayven
Link to comment
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"
Else
$net_test = "Not Connected"
EndIf
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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...