Home » Questions » Computers [ Ask a new question ]

Switch computer off automatically when the internet is disconnected

Switch computer off automatically when the internet is disconnected

Is there any free software that will detect the status of internet and shutdown the system when the internet disconnects?

Asked by: Guest | Views: 236
Total answers/comments: 2
Guest [Entry]

"A simple solution would write an AutoIt program that attempts to ping your internet service provider's DNS resolver. This is the only true way to detect if you're ""connected"" to the internet or not, since it's not always reliable to ping third party websites.

I would set it up to ping every minute, and if no response is received for 5 minutes, shut the computer down (or set it to go to sleep mode). Fortunately, AutoIt has a built-in Ping() and Sleep() functions.

The simple script would look like the following:

Local $i = 0
While $i < 5 ; Looping until we hit 5 attempts...
If Ping(""12.34.56.78"", 10000) == 0 Then ; If we couldn't ping...
$i = $i + 1 ; Increment the counter.
Else ; Else, if we could,
$i = 0 ; Reset the counter.
EndIf
Sleep(60000) ; Finally, loop every minute.
WEnd

; If the script gets here, we missed 5 pings - take action.
Shutdown(32) ; See the Shutdown() documentation, this makes the PC sleep.
; http://autoitscript.com/autoit3/docs/functions/Shutdown.htm

Before you run the computer overnight, you could then just execute the above script. To continue using your computer normally, simply close the script.

Disclaimer: I have not tested this code (I wrote it quickly in Notepad++), but it looks viable."
Guest [Entry]

"There is a download manager called FlashGet that has this feature built in.

From the menu documentation:

Shut Down When Done: When this is set,
FlashGet will disconnect from internet
and shutdown your computer on exit
(usefull if you leave your PC turned
on only to download files)."