If !skip!=0 if "x%%a"="xReceived" if "x%%c"="x1," set state=still on enableextensions offįor /f "tokens=2,3 delims=/ skip=16" %%i in (CheckPCs.bat) do ( As mentioned by others you will have to modify the code further for other localizations and for IPV6. I have the file saved as CheckPCs.bat and though I'm guessing it's not proper coding practice, I do have the IP addresses listed below the code along with a description which in my case is the physical location of the PC. I found that I could add a second variable to track that it was unreachable rather than exiting the loop and now this code is now running perfectly for me. Since using a goto in a for loop breaks out of all for loops not just the lowest nested for loop, PaxDiablo's code stopped processing further IP addresses when it got to one that was unreachable. My objective was to loop through a list of IP addresses to see if any were left on, and this code is to be run at the end of the last shift of the weekend to check if everyone is following the instructions to shut down all PCs before they go home. I've modified PaxDiablo's code slightly to better fit with what I was doing and thought I'd share. If no ping response from google DNS then start repair, i had static IP set for this purpose but it should work with dinamic as well. If "x%%a"="xReceived" if "x%%c"="x1," goto :upĮcho starting Repairing at ?te% %time%>D:\connection.log This is my modification to check and IP (local machine), good for case which connection is dropped either from dhcp server or any other issue, tested Under WinXP PRO SP3Ĭheckconnection.cmd: enableextensions off However, as Gabe points out in a comment, you can just use ERRORLEVEL so the equivalent of that second script above becomes: enableextensions off To only notify you when the state changes, you can use: enableextensions offįor /f "tokens=5,7" %%a in ('ping -n 1 !ipaddr!') do ( Do a test ping to discover what keyword is used in your locale. Take into account that, if your locale is not English, you must replace Received with the corresponding keyword in your locale, for example recibidos for Spanish. If "x%%a"="xReceived" if "x%%c"="x1," set state=upĬall it with the name (or IP address) you want to test: checklink 127.0.0.1 enableextensions offįor /f "tokens=5,6,7" %%a in ('ping -n 1 !ipaddr!') do ( It relies on the fact that you can do a single-shot ping and that, if successful, the output will contain the line: Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),īy extracting tokens 5 and 7 and checking they're respectively "Received" and "1,", you can detect the success. The following checklink.cmd program is a good place to start.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |