2

In order to work around some problems with some unreliable 2G/3G mobile broadband connections I would like to set up an automatic service to forcibly restart either the network interface itself or the whole computer once the internet connection has been down for a certain number of hours. This would automate what we so far have been doing manually to restore the connections.

Does such a utility exist for Windows 8 and if not how can I script such a task?


For a bit of context we have been installing a set of computers in inaccessible locations as a means of remotely monitoring installations of a system being tested. Anyway, these are plain old Windows 8 netbooks running a logging/configuration program and are typically connected through 2G/3G dongles.

Unfortunately for whatever reason these connections tend to be rather dodgy and drop out after a few months, requiring a manual restart. The ISP has been of little help, essentially claiming that their modern consumer gear isn't designed for this type of application (fair enough) but also unable to suggest any alternatives.

To be fair there do seem to be industrial modem/router devices available on the market, though the order-of-magnitude price difference and the fact that the systems have already been installed has me searching for easy solutions.

Lastly I am not an "superuser" and this is my first question or activity of any sort here, so I apologize if this is off-topic or a question which has already been answered.

2

You can write a batch script that pings some website that's almost never down(Google!) and you can detect if your internet is working with that script. Once the detecting part is done, its really easy to restart PC or a dial-up connection from batch file. Here's my sample script:

@echo off
:begin
ping www.google.com | find "Reply" > nul
if errorlevel 1 goto :failed
goto :OK

:failed
echo Failed
choice /T 3600 /D Y /N
rasdial <dial-up connection name> <username> <password>
goto begin

:OK
echo OK
goto begin
  • Thank you! I'll use your script as a skeleton and try adapting our needs, after taking a moment to brush up on my scripting anyway (I'd never have thought of using choice as a timer.) – doynax Mar 11 '14 at 16:25
  • I used to use this because my internet connection was fiddly. I'd just put it in start-up and let it do the rest. – tumchaaditya Mar 12 '14 at 20:50
0

For the record here is the script I ended up with after tinkering around with tumchaaditya's solution.

It has yet to be triggered in-the-wild but seems to work when tested. I shall amend this post once it does.

In theory the bandwidth consumption from the continual pings will add up to about 1.5 GB/year, so a periodic test may be preferable. However my ISP claims to only count actual payload bytes and I'm hoping that the continuous activity may serve as a keepalive.

@echo off
set INTERFACE="Local Area Connection"
set TIMEOUT=3600
set IP=8.8.8.8
set LOG="watchdog.log"

echo %DATE% %TIME%: Watchdog started >> %LOG%

:loop
rem First check the interface for an hour by pinging the Google DNS
rem and resetting the networking interface if it should fail.
ping -n %TIMEOUT% -w 1000 -l 0 %IP%
if %errorlevel% NEQ 1 goto :loop
echo %DATE% %TIME%: Connection failed. Restarting interface.. >> %LOG%
netsh interface set interface %INTERFACE% disable
netsh interface set interface %INTERFACE% enable

rem Give it another shot but restart the whole computer if it the communication should still fail
ping -n %TIMEOUT% -w 1000 -l 0 %IP%
if %errorlevel% NEQ 1 goto :loop
echo %DATE% %TIME%: Still no connection. Restarting computer.. >> %LOG%
shutdown /r /c "Internet wathchdog"

echo %DATE% %TIME%: Waiting for system to shut down >> %LOG%
choice /T %TIMEOUT% /D Y /N > NUL
echo %DATE% %TIME%: Gave up on the shut down attempt. Trying again.. >> %LOG%
goto :loop

Note that restarting the network interface requires administrative privileges (curiously rebooting the machine does not.)

Also beware that the exit status of ping is apparently still 0 for any non-responsive systems on the same subnet.

I was too lazy to investigate how to set up a proper daemon so the I must confess to running the script by creating a link to it in the autostart, setting the account to automatically log-on, marking the link to be run as administrator, and disabling UAC.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.