Jump to content
Sign in to follow this  
ycomp

detecting loss of internet connection?

Recommended Posts

Hi,

I would like to detect if the internet connection has been lost from within my script, while script is running. What is the best way to go about doing this with autoit?

Share this post


Link to post
Share on other sites

Hi,

I would like to detect if the internet connection has been lost from within my script, while script is running. What is the best way to go about doing this with autoit?

well this might be crazy but here goes

if your were not connected to the internet, perhaps your ip address would be a blank string returned with @IPAddress1

so you could have in your while loop a check like

While 1
If @IPAddress1 <> "" Then
;your stuff
;can go
;here
Else
MsgBox(0, "", "Connection lost")
ExitLoop
EndIf
WEnd

this might work, but i can't really give a guarantee.

:D

Share this post


Link to post
Share on other sites

;
If NOT _Connect_Status() Then MsgBox(0, "Connection Status", "The internet connection has been lost")
Func _Connect_Status()
   $cStatus = DllCall("WinInet.dll", "int", "InternetGetConnectedState", "int_ptr", 0, "int", 0)
   Return $cStatus[0]
EndFunc   ;<===> _Connect_Status()
;

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

thanks guys for the answers... think I'll go the InternetGetConnectedState route (no pun intended :D

Share this post


Link to post
Share on other sites

;
If NOT _Connect_Status() Then MsgBox(0, "Connection Status", "The internet connection has been lost")
Func _Connect_Status()
   $cStatus = DllCall("WinInet.dll", "int", "InternetGetConnectedState", "int_ptr", 0, "int", 0)
   Return $cStatus[0]
EndFunc  ;<===> _Connect_Status()
;
if you guys try this code on XP, do you get a "int_ptr" has been deprecated message? I am on vista and get that message so changed to "int".. question is, will that work on XP as "int" ?

Share this post


Link to post
Share on other sites

;
 If NOT _Connect_Status() Then MsgBox(0, "Connection Status", "The internet connection has been lost")
 Func _Connect_Status()
    $cStatus = DllCall("WinInet.dll", "int", "InternetGetConnectedState", "int_ptr", 0, "int", 0)
    Return $cStatus[0]
 EndFunc  ;<===> _Connect_Status()
;
What if you have a router? Doesn't this just check that the network card is active?

Share this post


Link to post
Share on other sites

I did some Googling on this last night. It checks for Proxy settings, and other tale-tell signs that you "should" have an internet connection. But, even the MSDN page for the function says that this is no indicator that access to any specific host is working, and recommends you use another function to ensure you can still connect to that specific place. This would be a good thing to run before trying to ping someone, it returns really fast, and helps to eliminate more possible places for it to fail.

As for the "int_ptr", when you try to run the function in SciTe, it tells you how to fix it. Do what it says.

Share this post


Link to post
Share on other sites

What if you have a router? Doesn't this just check that the network card is active?

I pulled that code from a monitor I put together a while back. At the time my ISP was having some connectivity issues and this told me when they were down.

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  

×
×
  • Create New...