Jump to content
Sign in to follow this  
John117

How to detect internet lost/reconnected

Recommended Posts

John117

Hey guys, I am looking for a quick way to check internet status using no bandwidth and little cpu. Vista currently provides info which reads 'Access: Local and Internet"

Is there a method of getting my yes or no from that source quickly? Thanks!

Edited by Hatcheda

Share this post


Link to post
Share on other sites
Yashied

Hey guys, I am looking for a quick way to check internet status using no bandwidth and little cpu. Vista currently provides info which reads 'Access: Local and Internet"

Is there a method of getting my yes or no from that source quickly? Thanks!

; #FUNCTION# ==============================================================================================================
; Function Name:    _IsInternet
; Description:      Check for Internet connection.
; Syntax:           _IsInternet (  )
; Parameter(s):     None.
; Return Value(s):  Success: Returns 1.
;                   Failure: Returns 0 and sets the @error flag to non-zero. @extended flag will contain the error code
;                            are specific to the WinINet functions.
;
; Author(s):        Yashied
; Note(s):          -
;==========================================================================================================================

func _IsInternet()
    
    local $Ret = DllCall('wininet.dll', 'int', 'InternetGetConnectedState', 'dword*', 0x20, 'dword', 0)
    
    if (@error) then
        return SetError(1, 0, 0)
    endif
    
    local $wError = _WinAPI_GetLastError()
    
    return SetError((not ($wError = 0)), $wError, $Ret[0])
endfunc; _IsInternet
Edited by Yashied

Share this post


Link to post
Share on other sites
John117
; #FUNCTION# ==============================================================================================================
; Function Name:    _IsInternet
; Description:      Check for Internet connection.
; Syntax:           _IsInternet (  )
; Parameter(s):     None.
; Return Value(s):  Success: Returns 1.
;                   Failure: Returns 0 and sets the @error flag to non-zero. @extended flag will contain the error code
;                            are specific to the WinINet functions.
;
; Author(s):        Yashied
; Note(s):          -
;==========================================================================================================================

func _IsInternet()
    
    local $Ret = DllCall('wininet.dll', 'int', 'InternetGetConnectedState', 'dword*', 0x20, 'dword', 0)
    
    if (@error) then
        return SetError(1, 0, 0)
    endif
    
    local $wError = _WinAPI_GetLastError()
    
    return SetError((not ($wError = 0)), $wError, $Ret[0])
endfunc; _IsInternetoÝ÷ Ûú®¢×£
÷N§Â0jÉ÷ö×±¥ç-x,¢g­)à²Ú²Ö§u×­j)^^jǬyæÞ0«H«Þ¶¸vÚ¢Ú-zËbµ©ÝëfzIèÂ0"­¶µ¢½«Þ¶¸uæö«¦åy©Ý¢yrëtßÛ0éȺǭí7ë+®ÈÁ«!¢bhël¢g­)à)iÊ'²Ö§·[§¶)H¶êç¡÷æË«zW¬²Ø^­Ólº{bn®x­m§$¢{azx·]ý±¨tájy,²®r÷jëh×6#Region ;Includes
#include <Date.au3>
#EndRegion 
HotKeySet("{ESC}", "TerminateApp")

While 1
    Sleep(1000)
    _IsInternet()
WEnd

; #FUNCTION# ==============================================================================================================
; Function Name:    _IsInternet
; Description:      Check for Internet connection.
; Syntax:           _IsInternet (  )
; Parameter(s):     None.
; Return Value(s):  Success: Returns 1.
;                   Failure: Returns 0 and sets the @error flag to non-zero. @extended flag will contain the error code
;                            are specific to the WinINet functions.
;
; Author(s):        Yashied
; Note(s):          -
;==========================================================================================================================

func _IsInternet()
    
    local $Ret = DllCall('wininet.dll', 'int', 'InternetGetConnectedState', 'dword*', 0x20, 'dword', 0)
    
    if (@error) then
        return SetError(1, 0, 0)
    endif

    local $wError = _WinAPI_GetLastError()
        
    return SetError((not ($wError = 0)), $wError, $Ret[0])
    ToolTip($Ret & " "   & _NowCalc(), 0, 0)
endfunc; _IsInternet






Func TerminateApp()
    Exit 0
EndFunc   ;==>TerminateApp
Edited by Hatcheda

Share this post


Link to post
Share on other sites
Authenticity

You don't need to get the last error. It returns true if connected, false otherwise.

Share this post


Link to post
Share on other sites
GEOSoft

In addition to Authenticity's post;

$Rtn is an array. The only element you are interested in is $Rtn[0]

Unless for debug purposes there is no need to return the error using the WinAPI udf. That file icludes far too much code to use it for reurning an error that you don't care about anyway.

And to close out. Your tool tip will never get called. Once you return from a function, that's it, no more lines in the function are read.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
John117

ok, got it!

#Region ;Includes
#include <Date.au3>
#EndRegion 
HotKeySet("{ESC}", "TerminateApp")

While 1
    Sleep(1000)
    _IsInternet()
WEnd

; #FUNCTION# ==============================================================================================================
; Function Name:    _IsInternet
; Description:      Check for Internet connection.
; Syntax:           _IsInternet (  )
; Parameter(s):     None.
; Return Value(s):  Success: Returns 1.
;                   Failure: Returns 0 and sets the @error flag to non-zero. @extended flag will contain the error code
;                            are specific to the WinINet functions.
;
; Author(s):        Yashied
; Note(s):          -
;==========================================================================================================================

func _IsInternet()
    
    local $Ret = DllCall('wininet.dll', 'int', 'InternetGetConnectedState', 'dword*', 0x20, 'dword', 0)
    ToolTip($Ret[0] & " "   & _NowCalc(), 0, 0)
    if (@error) then
        return SetError(1, 0, 0)
    endif
    
endfunc; _IsInternet

Func TerminateApp()
    Exit 0
EndFunc   ;==>TerminateApp

Edit: Is this clean? could it cause any problems as is? Could I run in to errors? very important that it doesnt mess up my script . . .

Edited by Hatcheda

Share this post


Link to post
Share on other sites
GEOSoft

func _IsInternet()
    
    local $Ret = DllCall('wininet.dll', 'int', 'InternetGetConnectedState', 'dword*', 0x20, 'dword', 0)
    ToolTip($Ret[0] & " "   & _NowCalc(), 0, 0)
   Return $Ret[0];;  In case you want to do something with the return value
endfunc; _IsInternet

Func TerminateApp()
    Exit 0
EndFunc  ;==>TerminateApp


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
martin

Tanks!

You might not have solved your problem with the function InternetGetConnectedState because, despite its name, it doesn't check that there is a connection to the internet. You need to use ping.

This post answered a very similar question.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
John117

You might not have solved your problem with the function InternetGetConnectedState because, despite its name, it doesn't check that there is a connection to the internet. You need to use ping.

This post answered a very similar question.

Martin, thanks for the reply! - Testing out your download now. frequent calls and slowing will be a prob otherwise. -it will be called about 100 times a sec . . . . depending on how fast I can keep my loop . . . .

Share this post


Link to post
Share on other sites
John117

You might not have solved your problem with the function InternetGetConnectedState because, despite its name, it doesn't check that there is a connection to the internet. You need to use ping.

This post answered a very similar question.

Come to think about it . . . how much will google like me if I ping them 52 million times this year :-P

was mostly needing to check if my wireless dropped anyway. I never loose internet. just connection to my wireless. :-) Thanks though . . .

Share this post


Link to post
Share on other sites
GEOSoft

func _IsInternet()
   Local $iConnected = 1
   local $Ret = DllCall('wininet.dll', 'int', 'InternetGetConnectedState', 'dword*', 0x20, 'dword', 0)
   If $Ret[0] Then
      Return SetError(0)
   Else
     ;; By moving the tooltip here it only displays if there is a problem
      ToolTip("No Internet Connection  " & _NowCalc(), 0, 0, "Internet Status", 2, 5)
      Return SetError(1)
   EndIf
endfunc; _IsInternet

Edited for stupidity. Obviously if $Ret[0] = 0 Then You can't ping anything anyway.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.