Modem Reboot
by dwarfsoft on Feb.17, 2009, under Home, Scripting
I have found myself having a very strange modem “freeze” issues. When traffic gets too high the modem WAN port freezes up. The LAN interface and DHCP server stay up, however the modem doesn’t even attempt to authenticate with the ISP. This lead me to learn a few different things in order to fix my issue. I used this code as a basis.
URLGetAuth Function
Function URLGetAuth(URL, Username, Password) Set Http = CreateObject("Microsoft.XMLHTTP") Http.Open "GET",URL,False, Username, Password Http.Send pagestatus = Http.status URLGetAuth = Http.responseText End Function
The above function has been extended to wait for the GET request to finish and provide authentication. The Check for Status code 200 has been removed so that any text is returned.
URLPostAuth Function
Function URLPostAuth(URL,FormData,Boundary,Username,Password) Set Http = CreateObject("Microsoft.XMLHTTP") Http.Open "POST",URL,True, Username, Password Http.send FormData for n = 1 to 50 If Http.readyState = 4 then exit for WScript.Sleep(1000) next If Http.readyState <> 4 then URLPostAuth = "Failed" else URLPostAuth = Http.responseText end if End Function
This function has been modified so that it can do an Authenticated POST to the Modem, but also so that it waits for the POST to complete instead of doing a shell.popup. It will wait for 50 seconds before failing.
Main Code
Username = InputBox("Enter the Modem Username:","Enter Username","") Password = InputBox("Enter the Modem Password:","Enter Password","") IP = InputBox("Enter the Modem IP Address:","Enter IP Address","") Set objRegEx = CreateObject("VBScript.RegExp") objRegEx.Pattern = ".*Down.*" Do While true status = URLGetAuth("http://" & IP & "/setup.cgi?next_file=Status.htm",Username,Password) Set colMatches = objRegEx.Execute(status) If colMatches.Count > 0 Then post = URLPostAuth("http://" & IP & "/setup.cgi?next_file=Reboot.htm", _ "todo=reboot&h_reboot=1&this_file=Reboot.htm&next_file=index.htm&message=", _ "",Username,Password) End If Loop
Firstly the Username, Password and IP address are collected, so that they don’t need to be already in the script. After the GET is called the RegEx is used against the status page to see if “Down” is found. If the Modem is down then the Reboot POST is called. I have recreated the POST method above using the available input fields for the Reboot page.
I have now removed the loop and added this as a Scheduled Task that runs every 10 minutes. This now keeps my connection alive when things go pearshaped.
Cheers, Chris.
