Sign in to follow this  
Followers 0
DCCD

Check Internet Connection

7 posts in this topic

hey

i wanna check my Internet connection, if Not able to connect to internet, I have to check it again and again "HOW"

$ping = Ping("www.google.com")
If $ping > 0 then
    My Script etc...
Else 
    I have to check it again and again "HOW"
EndIf

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Run the TestConnection function before any of your other code.

TestConnection()
While $AmIDoneYet = 1
MsgBox(0, "Test App", "Your Internet Is On!")
$AmIDoneYet = 0
Wend

Func TestConnection()
While $AmIConnected <> "True"
$ping = Ping("www.google.com")
If $ping > 0 then
    $AmIConnected = "True"
EndIf
WEnd
EndFunc

Of course, this will use 100% CPU and run until it connects to the internet, or you close it manually. You'll have to set it to check every 20 seconds or so, can just add a simple Sleep(20000) after the EndIf within the TestConnection function. Or however else you want to do it, but theres your internet connection test function.

Edited by jrowe

Share this post


Link to post
Share on other sites

Newp, just means you have to declare the variable. In the messagebox, notice that theres a "^" pointing at where the error occurs, this lets you know where something is going wrong.

$AmIDoneYet = 1

TestConnection()

While $AmIDoneYet = 1
MsgBox(0, "Test App", "Your Internet Is On!")
$AmIDoneYet = 0
Wend

Func TestConnection()
Local $AmIConnected = "init"
While $AmIConnected <> "True"
$ping = Ping("www.google.com")
If $ping > 0 Then
    $AmIConnected = "True"
EndIf
WEnd
EndFunc

This is just random, stream of consciousness programming, and in no way should your scripts be modeled on this style. I'd recommend going through the AutoIt 1-2-3 lessons, they'd help you alot :P

Share this post


Link to post
Share on other sites

Try this.... note that google won't always return a ping response sometimes even if you are connected to the inet and google is up.

$ping = Ping("www.google.com")
If Not @error Then
    ;do script here
Else
    Do
        $ping = Ping("www.google.com")
    Until Not @error
    ;do script here
EndIf

Share this post


Link to post
Share on other sites

DCCD

Another way:

$connect = _GetNetworkConnect()

If $connect Then
    MsgBox(64, "Connections", $connect)
Else
    MsgBox(48, "Warning", "There is no connection")
EndIf

Func _GetNetworkConnect()
    Local Const $NETWORK_ALIVE_LAN = 0x1  ;net card connection
    Local Const $NETWORK_ALIVE_WAN = 0x2  ;RAS (internet) connection
    Local Const $NETWORK_ALIVE_AOL = 0x4  ;AOL
    
    Local $aRet, $iResult
    
    $aRet = DllCall("sensapi.dll", "int", "IsNetworkAlive", "int*", 0)
    
    If BitAND($aRet[1], $NETWORK_ALIVE_LAN) Then $iResult &= "LAN connected" & @LF
    If BitAND($aRet[1], $NETWORK_ALIVE_WAN) Then $iResult &= "WAN connected" & @LF
    If BitAND($aRet[1], $NETWORK_ALIVE_AOL) Then $iResult &= "AOL connected" & @LF
    
    Return $iResult
EndFunc

:P

2 people like this

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  
Followers 0