Solved Batch remote reboot frozen router

November 21, 2013 at 05:33:37
Specs: Windows XP, HexaCore AMD FX-6100, 1400 MHz (7 x 200) / 4gb DDR
Hi I was wondering if anyone else liked this Script I found online:
http://www.makionv.com/2011/05/how-...

The reason this IS a Question is I searched HI and LO for this code, while I am happy to have found it, it's rather bulky and tricky to get working and I am hoping someone else here on Computing net can simplify it and condense it a little ?

I have re-written some of the code in my actual BATCH FILE but the script in the VBS file is almost unchanged except for my PATH statement. One of my main complaints when first trying to run this was a missing file called libsasl.dll which I was able to find online here http://www.dll-files.com/dllindex/d...

Then I had to Install or rather extract the files for CURL this was a headache also because some version would not work easily for me, I eventually got this one
libcurl-7.19.3-win32-ssl-msvc.zip from http://curl.haxx.se/latest.cgi?curl...

Finally I got it to work, after I found the missing file libsasl.dll As I am running Windows XP SP3 I figured others might also have these problems which is why I am posting this to both try and find an easier way of doing this and perhaps to help others who run into this problem.

Their are literally thousands of cheap ROUTERS in use today, many crash, freeze, or simply have partial connectivity after a few hours, or days so this tool is very useful in my opinion because it enables a user to schedule a PING request to an online server and Automatically REBOOT the router at the first sign of trouble.


I will start with the simple files first the TEXT file which only contains the IP address of the ROUTER.

NETGEAR.TXT | One entry inside text file | i.e. 192.168.2.1
:: ############################## your LAN ip

Next my BATCH file which I have just got working so it is a little cluttered for the moment, but it works fine for me.

:: BEGINE BATCH FILE CALLED 'REBOOT.BAT'

@echo off
setlocal enabledelayedexpansion
:: Check if internet is up or down
if exist nul del nul
ping -n 1 google.com > nul
goto %errorlevel%

:0
echo internet is up working fine
goto end

:1
echo Internet is not responding

:: @@@@@@@ NETGEAR ROUTER REBOOT @@@@@@@
:: http://www.makionv.com/2011/05/how-...
:: ############# VARI START ############

if not exist libsasl.dll echo libsasl.dll is missing &&goto bad1
if not exist "E:\Program Files\Automation\MTNL\curl-7.28.1\curl.exe" goto bad
set curlpath="E:\Program Files\Automation\MTNL\curl-7.28.1
set lognetgr= --basic --user username:password --url "http://192.168.2.1/setup.cgi?todo=debug"
set state="C:\state\status.txt"
:: ###################### VARI END ######################
:: LOGS YOU INTO THE ROUTER TO ENABLE THE REBOOT FEATURE
%curlpath%\curl.exe"%lognetgr%
%curlpath%\curl.exe"%lognetgr%
:: ROOT OF DRIVE LETTER WHERE THESE FILES ARE RUN FROM
D:
echo %path%
echo.
echo Running Router Reboot CYCLE
if exist sleep.com sleep 5
cls
:: RUNS THE MAIN NETGEAR ROUTER REBOOT SCRIPT
netgear.vbs
goto end
:bad1
echo Missing files: libsasl.dll
pause
goto end

:bad
echo ERROR BAD PATH %curlpath%"
pause
cls
:end
cls
echo DONE!
if exist sleep.com sleep 5
endlocal
cls

:: END BATCH FILE CALLED 'REBOOT.BAT'

And finally the netgear.vbs which baffles me completely apart from the path to my netgear.txt
file

:: BEGIN NETGEAR.VBS

On Error Resume Next
'local machine
strComputer = "."
'data file with IP addresses
filespec="E:\Program Files\Automation\MTNL\curl-7.28.1\netgear.txt"
Dim objFSO, a, s, WshShell, Windir, i, objWMIService
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
s = objFSO.opentextfile(filespec,1,true).ReadAll
a = Split(s,vbCrLf)
Set WshShell = CreateObject("WScript.Shell")
WinDir = WshShell.ExpandEnvironmentStrings("%WinDir%")
For i=0 to UBound(a)
If Trim(a(i))<>"" Then
'Launch telnet session from the command line
WshShell.Run "telnet " & a(i)
'Wait until the application has loaded
WScript.Sleep 300
Set ColProcesses = objWMIService.ExecQuery("Select * from Win32_Process",,48)
For Each Process in ColProcesses
If Process.Name = "Telnet " & a(i) Then
WshShell.AppActivate Process.Name
End If
Next
wscript.sleep 200
WshShell.SendKeys "{ENTER}"
wscript.sleep 200
WshShell.SendKeys "reboot"
wscript.sleep 200
WshShell.SendKeys "{ENTER}"
wscript.sleep 200
End If
WshShell.SendKeys "{ENTER}"
Next

:: END NETGEAR VBS

If Dreams Come True Oleg Would be Famous so far he's very shy, so much for Being Famous ;) http://www.book-stores.com/angels-

message edited by Ortorea


See More: Batch remote reboot frozen router

Report •


✔ Best Answer
November 23, 2013 at 00:31:20
I don't have time to catch up with all this, but...

Michelle,
[1] Your earlier:

for /f "tokens=* delims=*" %%a in ('"tmp" ^| find /i "Average = " ') do set...

You don't need FIND; you need:

@echo off > NEWFILE & setLocal enableDELAYedeXpansioN
for /f "tokens=9" %%a in (tmp) do (
set T=%%a
)
set/a avg=!T:ms=!
echo !avg!


CAUTION: different flavors of PING may need a tweak.

[2]The above gets out the "ms" so you don't get the invalid # prob.

=====================
M2 Golden-Triangle



#1
November 22, 2013 at 03:04:35
I would like to improve this ROUTER REBOOT Script by Incorporating a PING compare algorithm for example store up to SAY about 3 entries i.e. 2 previous, ping's and the current 3rd ping is compared against both previous times and IF THE LAST PING has a time in MILLISECONDS much Greater than both the previous ping's then reboot router but I do not know how this can be done simply ?

Any help Much Appreciated

All in the Interest of Improving Network Connectivity Performance.

Michelle <3

PS, I am currently working on getting this to work so far no luck not sure what I am missing here ? (As part of a Ping compare system)

ping -n 1 startpage.com > tmp

:: ------------------------------------------------------------------------
for /f "tokens=* delims=*" %%a in ('"tmp" ^| find /i "Average = " ') do set avs=%%a


:: ------------------------------------------------------------------------


If Dreams Come True Oleg Would be Famous so far he's very shy, so much for Being Famous ;) http://www.book-stores.com/angels-

message edited by Ortorea


Report •

#2
November 22, 2013 at 08:29:55
Window's telnet doesn't accept standard streams, hence the sendKeys kludge, and it's not included with Win7 and up. That's why we have PuTTY, and its script friendly brother, Plink. Also, with Plink and a base64 encoding VBScript function, you could probably do away with the curl requirement.

How To Ask Questions The Smart Way


Report •

#3
November 22, 2013 at 08:58:04
Thanks for that Razor good to see your still about it's been a while :)

I am still using XP, with no plans to ever use Windows 7 and above with the latest security concerns coming out from snowden my fears were confirmed all this shift by M$ to make coding more unfriendly on 64 bit OS's it puts me right off. A German IT Firm has now classed Windows 7 and above dangerous so say the least.

Well back to the scripting if you see a way to do this with something else I am always Interested as I am sure the users of win7 and above will be.

Michelle xoxoxo

If Dreams Come True Oleg Would be Famous so far he's very shy, so much for Being Famous ;) http://www.book-stores.com/angels-


Report •

Related Solutions

#4
November 22, 2013 at 09:53:15
Troll response: You do realize the NSA backdoor rumors started with WinNT4, right? Although I'm not sure what you mean with, "M$ to make coding more unfriendly on 64 bit OS's." I'm not sure why an IT security firm would take the effort to single out Win7/8/RT, and ignore 2000 and XP, both of which will soon be forgoing security updates. Don't get me wrong; MS has done a lot of stupid things over the years. That's why you need to qualify your statements with examples.

As for scripting this on Win7, I'd probably use powershell and a raw TCP/IP connection.

How To Ask Questions The Smart Way


Report •

#5
November 22, 2013 at 09:59:39
Thanks Razor, oh M$ = MS same thing ;) from what I understand, previous back doors in MS OS's were too easy for many hackers to break into, so MS sought help from the NSA to incorporate a Back door only the elites could use, as a result most security software will take many years to find a way to plug those holes = Dangerous ref:
http://bgr.com/2013/08/21/microsoft...
http://www.v3.co.uk/v3-uk/news/2290...

End Troll Reply :)

Michelle <3

PS Of coarse some of what I spoke about is from memory from years ago and may not be mentioned in those articles, but I do remember M$ seeked help from the NSA on their new Windows 7

If Dreams Come True Oleg Would be Famous so far he's very shy, so much for Being Famous ;) http://www.book-stores.com/angels-

message edited by Ortorea


Report •

#6
November 22, 2013 at 10:17:43
I am still doing something practical though, trying to figure out why this is not working out, must be losing a few more brain cells :p

for /f "tokens=* delims=,=" %%a in ('find /i "Average" tmp.txt') do set avs=%%a

I basically want to colect a few AVERAGE ping responses into 1 file, each on a seperate line! Then I want ti scan current ping responses and compare them to previous ping times, and IF the ping responses are getting slower (higher values) then run my REBOOT.BAT above for the router, this way I will not be waiting for total loss of network connectivity but can have the ROUTER re-boot before that happens to improve uptime.

so

example Output here:

Pinging startpage.com [212.121.101.6] with 32 bytes of data:

Reply from 212.121.101.6: bytes=32 time=45ms TTL=54

Ping statistics for 212.121.101.6:

Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),

Approximate round trip times in milli-seconds:

Minimum = 45ms, Maximum = 45ms, Average = 45ms


1/ Collect Average = ?? to a fixed text file, every 20 minutes (based on my scheduled batch)
2/ Continue adding results to this text and make comparisons to the entries in it UNTIL a call to reboot is made, then delete used file.

This is in an area I have not dealt with before as its basically not just checking if 1==1 But rather:

IF NOW GTR EARLIER-50 (by 50% Run Reboot.bat)

But clearly I don't want to reboot just because of a one off lag issue that might be temporary but build a list over say 1 hour and if it is still getting worse then reboot router.

Make sense ?

Michelle xoxoxo

If Dreams Come True Oleg Would be Famous so far he's very shy, so much for Being Famous ;) http://www.book-stores.com/angels-

message edited by Ortorea


Report •

#7
November 22, 2013 at 10:55:09
At last got the first part working yippee

@echo off
setlocal enabledelayedexpansion
ping -n 1 startpage.com > tmp.txt

:: ------------------------------------------------------------------------
for /f "tokens=4 delims=,= " %%a in ('find /i "Average" tmp.txt') do set avs=%%a
echo %avs%
>> pinglog.txt echo %avs%
pause
cls
endlocal

Now I am looking for the code that can extract each line from a text file to do some comparisons I found this code in the help made some changes to it.

FOR /f "tokens=1,2* delims=," %%i in (pinglog.txt) do @echo %%i %%j %%k

It echo's all the PING's but I have no idea how to put each ping into a separate variable so I can do a compare sum oO my mind boggles !!!


If Dreams Come True Oleg Would be Famous so far he's very shy, so much for Being Famous ;) http://www.book-stores.com/angels-

message edited by Ortorea


Report •

#8
November 22, 2013 at 15:21:45
OK I decided what I want to do, can someone help please ?

EXAMPLE OF MY TEXT FILE CONTENTS !
47ms
46ms
50ms
50ms
46ms
45ms
46ms

I need to get THE LAST 2 entries from a text file into:

var1
var2

To do a compare IF BOTH last 2 entries => 190 then DO goto

I just found this but NOT exactly what I want it returns to many entries, need last 2 lines adding together!
" target="_blank">http://www.computing.net/answers/pr...

I seem to be getting there but now I am getting an error in my SUM the error says.

54ms
Invalid number. Numeric constants are either decimal (17),
hexadecimal (0x11), or octal (021).
TOTAL=
YES FILE EXISTS
Press any key to continue . . .

And here is the code I have so far

:: START BATCH

@echo off
setlocal enabledelayedexpansion
:: +++++++++++++++++++++++++++++++++++++++++++++++++++++++
echo M2G
for /f "tokens=* delims= " %%a in (pinglog.txt) do (
set var1=%%a
)
echo !var1!
pause
cls
:: +++++++++++++++++++++++++++++++++++++++++++++++++++++++
ping -n 1 startpage.com > tmp.txt

:: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
for /f "tokens=4 delims=,= " %%a in ('find /i "Average" tmp.txt') do set var=%%a
echo !var!
>> pinglog.txt echo !var!

:: ------------------------------------------------------------------------

:: #############################################################
:: set /A TOTAL = !VAR! + !var1!
:: ------------------------------------------------------------------------
:: ERROR COMES FROM LINE BELOW
set /a pinged=%var%%+%var%
echo TOTAL=!pinged!
>> total-ms.txt echo !pinged!
if exist total-ms.txt echo YES FILE EXISTS &┬Čepad total-ms.txt
pause
cls
:: ############################################################
endlocal
cls

:: END BATCH


If Dreams Come True Oleg Would be Famous so far he's very shy, so much for Being Famous ;) http://www.book-stores.com/angels-

message edited by Ortorea


Report •

#9
November 22, 2013 at 20:36:40
Hello :O
Here's one version, but not much like yours because I like to avoid temp files etc.
It just repeats, without a wait, so a "sleep" might be in order to keep the pings from bogging things down. It only samples the last two pings, as per your specs:
@echo off & SETLOCAL
set prev=0
set x=0
:A
:: min, max, avg are all equiv. with only one sample
for /f "tokens=4 delims=m " %%a in ('ping -n 1 google.com^|find /i "average"') do set x=%%a
echo [%prev%--%x%]
if %prev% gtr 50 if %x% gtr 50 goto :SLOW
set prev=%x%
goto :a
:SLOW
echo SLOWing connection!

message edited by nbrane


Report •

#10
November 22, 2013 at 20:45:40
Oh dear nbrane you saved my mind from almost losing it, spent many hours trolling through dozens of pages on computing net found some similar but nothing like your wisdom can come up with, almost falling asleep now lol, but can't resist trying it out :)

Michelle xoxox

PS, I will most likely just run it from one of my other batch files that run about every 10 minutes by a simple CALL command

I will use this as a Guide for MIN / MAX Ping response time so I can be realistic on a safe setting, but ideally it is better to have the first ping and the second ping farther apart I can do with my sleep.com
http://serverfault.com/questions/14...

In fact as I think more on this! It might be a good idea to ALTERNATE 2 different sources for the ping, because if for what ever reason THEIR server was down and not my end, would be bad to try to correct a problem that was some one elses, so to ping address alternate each cycle ? not sure how to do that still studying your code but it works great thanks nbrane :)

If Dreams Come True Oleg Would be Famous so far he's very shy, so much for Being Famous ;) http://www.book-stores.com/angels-

message edited by Ortorea


Report •

#11
November 22, 2013 at 21:26:19
Dear nbrane how about this for checking against 2 sources as to ensure against false positives ?

:: BEGIN BATCH
@echo off & SETLOCAL
set prev=0
set x=0
set s=1
:A
if %s%==1 set domain=startpage.com
if %s%==2 set domain=google.com
if %s%==1 set s=2
if %s%==2 set s=1
if exist sleep.com sleep 10
:: min, max, avg are all equiv. with only one sample
for /f "tokens=4 delims=m " %%a in ('ping -n 1 %domain%^|find /i "average"') do set x=%%a
echo [%prev%--%x%]
if %prev% gtr 180 if %x% gtr 180 goto :SLOW
set prev=%x%
goto :a
:SLOW
echo SLOWing connection!
:: endlocal
:: END BATCH

If Dreams Come True Oleg Would be Famous so far he's very shy, so much for Being Famous ;) http://www.book-stores.com/angels-

message edited by Ortorea


Report •

#12
November 22, 2013 at 21:29:27
Hi :-)
Well, with someone like Google, or Yahoo, or most high-profile servers, I would expect their DNS service to forward any connect-requests to another available server, of which I expect there are hundreds if not more. I'm not at all knowledgable of these things. Ping or Tracert options might allow you to override forwarding by specifying "strict", but I've never delved that deep - I just grab-and-go! g'night, sw.dr.

Report •

#13
November 22, 2013 at 21:45:35
Night nbrane and thanks again your a Miracle worker :)

Michelle xoxoxo

If Dreams Come True Oleg Would be Famous so far he's very shy, so much for Being Famous ;) http://www.book-stores.com/angels-


Report •

#14
November 23, 2013 at 00:31:20
✔ Best Answer
I don't have time to catch up with all this, but...

Michelle,
[1] Your earlier:

for /f "tokens=* delims=*" %%a in ('"tmp" ^| find /i "Average = " ') do set...

You don't need FIND; you need:

@echo off > NEWFILE & setLocal enableDELAYedeXpansioN
for /f "tokens=9" %%a in (tmp) do (
set T=%%a
)
set/a avg=!T:ms=!
echo !avg!


CAUTION: different flavors of PING may need a tweak.

[2]The above gets out the "ms" so you don't get the invalid # prob.

=====================
M2 Golden-Triangle


Report •

#15
November 23, 2013 at 23:38:34
Thanks M2G We got it working already, but I did find one small bug with nbrane's script itsi witsi small bug, and I have added a flag to prevent multiple instances from running.

If the Internet is totally DOWN then: do set x=%%a
is NULL so can't change an earlier value in x, so my work around was as below! in bold
:: begin batch

@echo off & SETLOCAL
set state="C:\state\status.txt"
if exist sleep.com set doze=sleep 10
if not exist sleep.com set doze=echo NO-SLEEP FOR THE WICKED
:: ############################
if exist pingchk goto no-ping
:: ############################
set prev=0
set x=0
set s=1
> pingchk echo running prevents multiple instances from running
:A
if %s%==1 set domain=startpage.com
if %s%==2 set domain=yahoo.com
if %s%==1 set s=2
if %s%==2 set s=1
%doze%
:: min, max, avg are all equiv. with only one sample
for /f "tokens=4 delims=m " %%a in ('ping -n 1 %domain%^|find /i "average"') do set x=%%a
echo [%prev%--%x%]
if %prev% gtr 180 if %x% gtr 180 goto :SLOW
set prev=%x%
set x=1000
goto :a
:SLOW
if exist pingchk del pingchk
echo SLOWing connection! @ D: %date% T: %time%
:: ###################################################
REM if exist "Router-Reboot.bat" call "Router-Reboot"
:: ###################################################
endlocal
%doze%
:: ############################
:no-ping
:: ############################
cls

:: end batch


M2G I will also check out your script too thanks :)

Michelle xoxoxo

If Dreams Come True Oleg Would be Famous so far he's very shy, so much for Being Famous ;) http://www.book-stores.com/angels-

message edited by Ortorea


Report •

#16
November 24, 2013 at 00:44:57
Dear Mechanix2Go
I just tried you script, it works very well, the advantage of your script to me is that it can be Run in one time mode, like day 1 then day 3 and does not require me to keep a batch file running all the time in LOOP mode, I like both nrane's script and yours so can make use of both of them in different configurations, so yours can be called at any time without running until doomsday lol this will integrate nicely with my existing batch routines that run every 10 minutes already, however if their is a situation where the network is in persistent unstable mode then the LOOP batch made by nbrane can come into play thanks to both of you <3

It makes it much easier to call the ROUTER REBOOT script under various circumstance at the top of this post.

Michelle xoxoxo

PS, Not sure if its just my end but I notice that the more frequent pings are sent the slower they get :p and it just occured to me that I can use the %x% as my sleep %x% time lol

If Dreams Come True Oleg Would be Famous so far he's very shy, so much for Being Famous ;) http://www.book-stores.com/angels-

message edited by Ortorea


Report •

#17
November 24, 2013 at 07:34:06
Dear M2G

From your code and some I added TO CONTROL the times it runs, this is my result below!

:: BEGIN M2G BATCH CODE

@echo off
setlocal enabledelayedexpansion
set state="C:\state\status.txt"
if exist sleep.com set doze=sleep
if not exist sleep.com set doze=echo NO-SLEEP FOR THE WICKED
:: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
for /f "tokens=* delims= " %%a in (pinglog.txt) do (
set var1=%%a
)

echo !var1!
:: LIMITS SIZE OF pinglog.txt TO 6 bytes
for %%a in (pinglog.txt) do ( if %%~za gtr 6 del pinglog.txt
)
:: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ping -n 1 startpage.com > tmp
for /f "tokens=9" %%a in (tmp) do (
set T=%%a
)

set/a VAR2=!T:ms=!
echo !VAR2!
>> pinglog.txt echo !VAR2!

:: ------------------------------------------------------------------------
set /a pinged=%var1%+%var2%
echo TOTAL=!pinged!
>> total-ms.txt echo !pinged!
>> %state% echo on D: %date% T: %time% ping speed !pinged!
if "!pinged!" LSS "80" %doze% !pinged!
if "!pinged!" GEQ "80" %doze% 30
cls
endlocal

:: END M2G BATCH CODE

If Dreams Come True Oleg Would be Famous so far he's very shy, so much for Being Famous ;) http://www.book-stores.com/angels-

message edited by Ortorea


Report •

#18
November 24, 2013 at 15:58:36
Dear nbrane, and M2G,
I have now incorporated both your scripts with some code tweaking of my own, the following 2 batch files are now integrated to launch my ROUTER REBOOT Only if the pings are consistently bad, the way I have done this is to set a high ping to delete a flag called "pingchk"

When M2G's code detects an initial slowdown PINGED.BAT then launches reboot.bat which then goes into a loop check until "pingchk" is of a greater file size of 200 bytes, if during the cycle some large pings are detected then "pingchk" is reset (deleted) and is created immediately again as it is also used to flag that the loop is running. This prevents more than one instance of reboot.bat from running. I have also put several LOG exports to my main log-file %status%

Below are both my batch files, the first does a quick check, the second is launched for closer scrutiny, and if the router is then required to be rebooted this is done from reboot.bat

:: START PINGED BAT
@echo off
setlocal enabledelayedexpansion
D:
set state="C:\state\status.txt"
set pingchk=if exist "MTNL\curl-7.28.1\pingchk" goto no-ping
set router="D:\Program Files\Automation\MTNL\curl-7.28.1\reboot.bat"
if exist sleep.com set doze=sleep
if not exist sleep.com set doze=echo NO-SLEEP FOR THE WICKED
:: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
for /f "tokens=* delims= " %%a in (pinglog.txt) do (
set var1=%%a
)

echo !var1!
:: LIMITS SIZE OF pinglog.txt TO 6 bytes
for %%a in (pinglog.txt) do ( if %%~za gtr 6 del pinglog.txt
)

:: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ping -n 1 startpage.com > tmp
for /f "tokens=9" %%a in (tmp) do (
set T=%%a
)

set/a VAR2=!T:ms=!
echo !VAR2!
>> pinglog.txt echo !VAR2!

:: ------------------------------------------------------------------------
set /a pinged=%var1%+%var2%
echo TOTAL=!pinged!

>> %state% echo on D: %date% T: %time% ping speed !pinged!
if "!pinged!" LSS "80" %doze% !pinged!
if "!pinged!" GEQ "80" %doze% 30
%pingchk%
if exist %router% if "!pinged!" GEQ "160" echo RUNNING ROUTER
if exist %router% if "!pinged!" GEQ "160" start "Reboot-R" /D"D:\Program Files\Automation\MTNL\curl-7.28.1" /LOW reboot.bat

:no-ping
>> %state% echo PINGED.BAT CLOSING PINGED = !pinged!
echo PINGED.BAT CLOSING PINGED = !pinged!
sleep 5
cls
endlocal
:: END PINGED BAT


:: START REBOOT BAT
@echo off
setlocal enabledelayedexpansion
:: ############################
set state="C:\state\status.txt"
>> %state% echo STARTING ROUTER REBOOT.BAT CHECKING D:%date% T:%time%
if exist pingchk goto no-ping
:: ############################

:: ++++++ START Check if internet is up or down ++++++++
if exist sleep.com set doze=sleep 10
if not exist sleep.com set doze=echo NO-SLEEP FOR THE WICKED
set prev=0
set x=0
set s=1
> pingchk echo running prevents multiple instances from running and is a counter file
:A
if %s%==1 set domain=startpage.com
if %s%==2 set domain=google.com
if %s%==2 set s=1 &&goto swp
if %s%==1 set s=2 &&goto swp
:swp
%doze%
:: min, max, avg are all equiv. with only one sample
for /f "tokens=4 delims=m " %%a in ('ping -n 1 %domain%^|find /i "average"') do set x=%%a
echo [%prev%--%x%]
if %prev% gtr 180 if %x% gtr 180 goto :SLOW
set prev=%x%
if %x% gtr 150 >> %state% echo pingchk was deleted because A ping was: %x% @ %time%
if %x% gtr 150 del pingchk
>> pingchk echo %x%
:: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
for %%a in (pingchk) do ( if %%~za gtr 200 goto end
)
:: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
set x=1000
goto :a
:SLOW

echo SLOWing connection! @ D: %date% T: %time% %prev%--%x%
>> %state% echo SLOWing connection! @ D: %date% T: %time% %prev%--%x%
echo IF YOU HAVE NOT SET YOUR USER NAME AND PASSWORD BELOW
echo PLEASE LOOK FOR USERNAME:PASSWORD and change to those
echo for your router! Also set the IP address of Router @ --url!

%doze%
cls
:: ++++++++ END Check if internet is up or down +++++++++

:: @@@@@@@@@@@@@@@@ NETGEAR ROUTER REBOOT @@@@@@@@@@@@@@@
:: http://www.makionv.com/2011/05/how-...
:: ################# ROUTER VARI START ##################
if exist libsasl.dll if not exist "C:\WINDOWS\system32\libsasl.dll" copy libsasl.dll "C:\WINDOWS\system32\*"
if not exist "D:\Program Files\Automation\MTNL\curl-7.28.1\curl.exe" goto bad
set curlpath="D:\Program Files\Automation\MTNL\curl-7.28.1
set lognetgr= --basic --user USERNAME:PASSWORD --url "http://192.168.2.1/setup.cgi?todo=debug"

:: ################## ROUTER VARI END ###################
%curlpath%\curl.exe"%lognetgr%
%curlpath%\curl.exe"%lognetgr%
if not exist "C:\WINDOWS\system32\choice.com" goto run
cls
C:
:: -----------------------------------------------------------
echo.
echo.
echo.
echo ---------------------------------------------------------------
echo Please press (A) To ABORT REBOOTING ROUTER !!!
echo Please press (B) reboot router now or wait (10 Secs)
echo ---------------------------------------------------------------
choice /t:b,10/c:ab
if errorlevel 2 goto run
if errorlevel 1 goto end
:: -------------------------------------------------------------
goto end
:run
cls
D:
echo %path%
echo.
echo Running Router Reboot CYCLE
%doze%
netgear.vbs
if not exist %state% goto skip
>> %state% echo -------------------------------------------------------------------
>> %state% echo THE NETGEAR ROUTER HAS BEEN REBOOTED on
>> %state% echo %date% @ %time% Previous Ping:%prev% Latest Ping:%x%
>> %state% echo -------------------------------------------------------------------
cls
goto skip
:bad
D:
echo ERROR BAD PATH %curlpath%"
echo Missing curl.exe
%doze%
cls
:end
if not exist %state% goto skip
>> %state% echo -------------------------------------------------------------------
>> %state% echo THE NETGEAR ROUTER WAS NOT REBOOTED on
>> %state% echo %date% @ %time% Previous Ping:%prev% Latest Ping:%x%
>> %state% echo -------------------------------------------------------------------
:skip
D:
cls
echo DONE!
%doze%
if exist pingchk del pingchk
:: ############################
:no-ping
>> %state% echo CLOSING ROUTER REBOOT.BAT CHECKING D:%date% T:%time%
endlocal
:: ############################
cls
:: END REBOOT BAT

My Batch files now log entries to my live log file
http://tinyurl.com/d2mv9na

If Dreams Come True Oleg Would be Famous so far he's very shy, so much for Being Famous ;) http://www.book-stores.com/angels-

message edited by Ortorea


Report •

Ask Question