Jump to content

Check Internet Connection


DCCD
 Share

Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
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

Link to comment
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

Link to comment
Share on other sites

  • 9 years later...
If _IsInternetConnected() Then
    msgbox(0,"True","Internet Connected")
Else
    Msgbox(0,"False","Internet Disconected")
Endif
Func _IsInternetConnected()
Local $aReturn = DllCall('connect.dll', 'long', 'IsInternetConnected')
If @error Then
Return SetError(1, 0, False)
EndIf
Return $aReturn[0] = 0
EndFunc ;==>_IsInternetConnected

That is my func I alsway to check

Link to comment
Share on other sites

  • Moderators

tungpheng,

The fact that the post above yours is from 10 years ago somehow escaped your notice? Please do not necro-post like this again.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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...