Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » XP Batch script: Ping all PC's, if they all are offline: reboot router
Closed Thread
Old 12-16-2007, 05:19 AM   #1 (permalink)
 
Newb Techie

Join Date: Oct 2007

Posts: 25

LincolnX is on a distinguished road

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

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.
LincolnX is offline  
Old 12-19-2007, 03:34 PM   #2 (permalink)
 
Newb Techie

Join Date: Oct 2007

Posts: 25

LincolnX is on a distinguished road

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

*Ahum*
LincolnX is offline  
Old 12-19-2007, 09:08 PM   #3 (permalink)
 
Monster Techie

Join Date: May 2004

Location: /usr/root/mn/us

Posts: 1,121

bla!! is on a distinguished road

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

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.
__________________
<br>
Its a frigging Laptop, not a Labtop!!!!
bla!! is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Boosting range of wireless router with a second unit. Jlagreca Computer Networking & Internet Access 2 06-16-2007 06:17 PM