XP Batch script: Ping all PC's, if they all are offline: reboot router

Status
Not open for further replies.

LincolnX

Baseband Member
Messages
25
Hello,

I would like to make a script which pings all pc's in my network (192.168.1.3 to 192.168.1.15) with a ping count of 1 and a timeout of 100 ms. If all PC's are offline the router need to be rebooted. If one PC is online, the computer doesn't need to do anything.

So this is what I have so far:
Code:
@echo off 
del /Q badhost.log
for /f %%I in (machines.txt) do (
ping -n 1 -w 100 %%I | find "Reply" > nul
if not errorlevel 1 echo %%I reachable >> badhost.log )

echo off
if NOT EXIST badhost.log goto reboot

:reboot
iexplore http://192.168.1.1/apply.cgi?action_mode=Save%26Restart+&current_page=SaveRestart.asp&wl_wep_x=0&wl_key1=&wl_key2=&wl_key3=&wl_key4=&next_page=Basic_SaveRestart.asp&sid_list=General%3B&group_id=&modified=0&act

However, it does not seem to work. In both scenario's I get a message that it's online AND offline.
 
It's rebooting every time because you have the :reboot at the bottom of the script.
You need to do the following

Code:
@echo off
goto start

:reboot
iexplore http://192.168.1.1/apply.cgi?action_mode=Save%26Restart+&current_page=SaveRestart.asp&wl_wep_x=0&wl_key1=&wl_key2=&wl_key3=&wl_key4=&next_page=Basic_SaveRestart.asp&sid_list=General%3B&group_id=&modified=0&act
goto end

:start
del /Q badhost.log
for /f %%I in (machines.txt) do (
ping -n 1 -w 100 %%I | find "Reply" > nul
if not errorlevel 1 echo %%I reachable >> badhost.log )

echo off
if not exist badhost.log goto reboot

:end

Nice job on the code btw.
 
Status
Not open for further replies.
Back
Top Bottom