ruelle Posted February 4, 2015 Share Posted February 4, 2015 (edited) I have a LAN with 4 PCs and one Synology server. I wish that every time a computer is turned off, it runs a batch (from windows pc) and see if other PCs are on, - if any is on do nothing, - otherwise runs a command that shuts down the server.Here is what I have at the moment: @echo off PING 192.168.1.10 IF %ERRORLEVEL% EQU 1 plink root@192.168.1.10 -pw MYPASSWORD shutdown -s -t 00But I would like to do something like: http://i.imgur.com/BLAVCBt.pngTHANK YOU!! Edited February 4, 2015 by ruelle Link to comment Share on other sites More sharing options...
jaclaz Posted February 4, 2015 Share Posted February 4, 2015 Something like:@ECHO OFFSETLOCAL ENABLEEXTENSIONSSET /A Points=0FOR /L %%A IN (10,1,14) DO CALL :DoPing 192.168.1.%%AIF %Points% GTR 0 plink root@192.168.1.10 -pw MYPASSWORD shutdown -s -t 00 GOTO :EOF :DoPingFOR /F %%B IN ('PING -n 1 %1 ^|FIND "TTL") DO SET /A Points+=1 http://ss64.com/nt/ping.html A successful PING does NOT always return an %errorlevel% of 0Therefore to reliably detect a successful ping - pipe the output into FIND and look for the text "TTL" jaclaz Link to comment Share on other sites More sharing options...
ruelle Posted February 4, 2015 Author Share Posted February 4, 2015 (edited) http://ss64.org/viewtopic.php?pid=8188 http://stackoverflow.com/questions/28304099/batch-script-to-ping-other-pc-in-my-lan-and-shutdown-together-last-online-pc http://www.msfn.org/board/topic/173438-shutdown-last-running-pc-on-the-lan-with-server/ http://forum.synology.com/enu/viewtopic.php?f=145&t=96609&p=364122#p364122 http://www.dostips.com/forum/viewtopic.php?f=3&t=6245 I think last one will be more easy to use thank you for the answer! @echo offset "flag="ping 192.168.1.1 -n 2 |find /i "TTL=" >nul && set flag=1ping 192.168.1.2 -n 2 |find /i "TTL=" >nul && set flag=1ping 192.168.1.3 -n 2 |find /i "TTL=" >nul && set flag=1ping 192.168.1.4 -n 2 |find /i "TTL=" >nul && set flag=1if not defined flag echo shutdown server Edited February 4, 2015 by ruelle Link to comment Share on other sites More sharing options...
jaclaz Posted February 5, 2015 Share Posted February 5, 2015 (edited) Sure, as the guy that provided it commented, for four PC's that is fine. The FOR /L loop utility becomes evident when you have the whole range 1÷255 to scan or more...... and the "points adding system" may come of use when (if) you need to add some other condition (like -say - a Ping result that is good but that has a too high TTL or response time) ... jaclaz Edited February 5, 2015 by jaclaz 1 Link to comment Share on other sites More sharing options...
gunsmokingman Posted February 5, 2015 Share Posted February 5, 2015 Here is a way of doing what you want, only using a VBS script'-> Wmi ObjectDim Wmi :Set Wmi = GetObject("winmgmts:\\.\root\cimv2")'-> Varibles For RuntimeDim Col, i, Ip, Obj'-> Array To Hold All The IP AddressesIp = Array("127.0.0.1","192,123,55,1","127.0.0.24","123.55.72.123")'-> Start First Loop Threw IP For Each i In Ip '-> Passing i As Ip Address To Be Ping Set Col = Wmi.ExecQuery("Select * From Win32_PingStatus where Address = '"&i&"'")'-> Second Loop To Ping Ip Address For Each Obj in Col If IsNull(Obj.StatusCode) Or Obj.StatusCode<>0 Then'-> Code Here For Computer That Does Not Respond Wscript.Echo "Computer Ping Missing : " & i Else'-> Code Here When The Computer Does Respond WScript.Echo "Computer Ping Confirm : " & i End If Next Next Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now