Windows Internet connection monitor and repair tool

Why - I have my internet connection through a wireless provider and have run into issues with it getting stuck and not routeing traffic. I found clicking on the connection in my task bar and choosing repair tended to fix the issue. This problem only seem to happen when I am using my bittorrent client which tells me its probably just a limitation on the wireless adapter that I am hitting.

What - I started looking for a windows solution to correct this issue or self-heal it when it became unresponsive. I really could not find anything and kept thinking if this were a unix box I could write a short script to take care of it. Then the giant light bulb went off over my head and I realized I could write a TCL script to do just that with ActiveTCL and a some windows knowledge.

How - First I downloaded and installed ActiveTCL from activestates website. I also needed a program called devcon that can be found on Microsofts website as a free download.

I created a directory on my system under c:\ called batch. This is where I will put all of these tools for future reference to the reader.

I put the devcon.exe file in c:\batch. You can use "devcon find =net" to find your interface. It will be a string that looks something like: ROOT\SOMETHING\ELSE NOTE: Remember to escape the \ like this \\ so that tcl does not choke on it.

The IP address that is being pinged is simply the gateway address of the router I connect to. I use only one ping and wait for a reply. If I get a "reply timed out" message, we correct the problem. Otherwise do nothing. If I do not get a Reply from message or timed out message I will go ahead and attempt to correct regardless.

Original Source - Please do not edit.

 wm withdraw .
 proc writelog {data} {
     set timestamp [clock format [clock seconds] -format {%D %X}]
     set fileId [open c:\\batch\\winnetfix.log a+]
     puts $fileId "$timestamp - $data"
     close $fileId
 }
 catch {exec c:\\windows\\system32\\ping.exe -n 1 192.168.1.1} result
     switch -glob $result {
         *from* {set connection 1}
         *timed* (set connection 0; writelog "Timed Out"}
         default {set connection 0; writelog "Default Used"}
     }
 if {$connection == 0} {
     catch {exec c:\\batch\\devcon.exe disable @USB\\VID_07B8&PID_6001\\6&3534C65&0&5 } disable
     catch {exec c:\\batch\\devcon.exe enable @USB\\VID_07B8&PID_6001\\6&3534C65&0&5 } enable
     writelog "Fixed Connection!"
     exit
 }
 exit

'''Revised Source''' - Feel free to correct

 wm withdraw .
 proc writelog {data} {
     set timestamp [clock format [clock seconds] -format {%D %X}]
     set fileId [open c:/batch/winnetfix.log a+]
     puts $fileId "$timestamp - $data"
     close $fileId
 }
 catch {exec c:/windows/system32/ping.exe -n 1 192.168.1.1} result
     switch -glob $result {
         *from* {set connection 1}
         *timed* (set connection 0; writelog "Timed Out"}
         default {set connection 0; writelog "Default Used"}
     }
 if {$connection == 0} {
     catch {exec c:/batch/devcon.exe disable @USB\\VID_07B8&PID_6001\\6&3534C65&0&5 } disable
     catch {exec c:/batch/devcon.exe enable @USB\\VID_07B8&PID_6001\\6&3534C65&0&5 } enable
     writelog "Fixed Connection!"
     exit
 }
 exit

RT For one, you can replace all the escaped backslashes in the first argument to exec and in the open command with a single forward quote. Don't replace backslashes in latter arguments to exec - 15Mar07

TJC Do you mean like in the Revised Source? - 15Mar07


Questions - If there are any questions or suggestions on how to make this better please feel free to add them here. I will be sure to keep an eye on this page to see what everyone comes up with. Tory Clement


One very minor thing. It is often important that the logged message describes EXACTLY what the program has done not the result that it expects ("Fixed Connection!") unless that result is thoroughly tested. May also be a good idea to include $enable in the log to record any errors raised.

 writelog "USB wireless device restarted.  Result: $enable"