Last active
November 13, 2024 07:30
-
-
Save Techlogist/f980d590a0caf75414750f25d2a1cbad to your computer and use it in GitHub Desktop.
Wake-On-LAN from a list in a text file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| REM License: GNU General Public License v2.0 | |
| REM Author: Miguel | |
| REM Website: www.techlogist.net | |
| REM Post: https://techlogist.net/uncategorised-en/wake-on-lan-from-a-list-in-a-text-file/ | |
| REM Description: Tries to wake all computers from a list in a TXT file | |
| REM ATTENTION: Its recommeded to have a static IP | |
| REM OS/Language/Region: Windows/EN-US | |
| :_start | |
| REM Start of script | |
| @echo off | |
| cls | |
| title Wake On LAN from list in text file | |
| color f0 | |
| mode con:cols=70 lines=15 | |
| goto _set_variables | |
| :_set_variables | |
| REM Set the path and name of the document where the computer details are. | |
| REM Document line Structure: Computer-Name;Computer-IP;Computer-MAC;Computer-Subnet;Computer-Port | |
| cls | |
| set _computer_doc=c:\pathToFile\Computers.txt | |
| REM Set the folders to be verified | |
| set _WolCmd-app=C:\ProgramFolder\WOLCMD | |
| REM Set the folder to output errors | |
| set _ErrorFolder=C:\pathToFolder\ErrorFolder | |
| goto _SetFileName | |
| :_SetFileName | |
| REM Set the daily WOL error report name | |
| set CurrentDatePre=%date:~4% | |
| set SetDate=%CurrentDatePre:/=-% | |
| set _DailyReport=WOL-Error-%SetDate%.txt | |
| set _OutputError="%_ErrorFolder%\%_DailyReport%" | |
| goto _WolCmd | |
| :_WolCmd | |
| REM Set the WolCmd.exe path as a variable | |
| cls | |
| cd "%_WolCmd-app%" | |
| REM Check if WolCmd.exe is available | |
| IF EXIST "%_WolCmd-app%\WolCmd.exe" (goto _wake_computers) else (goto _WolCmd_unavailable) | |
| goto _WolCmd | |
| :_WolCmd_unavailable | |
| REM The error screen for WolCmd is missing | |
| color 47 | |
| cls | |
| echo ---------------------------------------------------------------------- | |
| echo. | |
| echo. | |
| echo. | |
| echo. | |
| echo. | |
| echo WolCmd is unavailable. Please install | |
| echo. | |
| echo. | |
| echo. | |
| echo. | |
| echo. | |
| echo ---------------------------------- ---------------------------------- | |
| pause | |
| color f0 | |
| goto EOF | |
| :_wake_computers | |
| REM Run the tasks | |
| color f0 | |
| cls | |
| echo ---------------------------------------------------------------------- | |
| echo. | |
| echo. | |
| echo Wake-On-Lan Computers | |
| echo. | |
| echo. | |
| echo. | |
| echo. | |
| echo. | |
| echo. | |
| echo. | |
| echo. | |
| echo ---------------------------------- ---------------------------------- | |
| timeout /T 2 >nul | |
| cls | |
| goto _send_wol | |
| :_send_wol | |
| REM Send the signal | |
| cd "%_WolCmd-app%" | |
| echo. | |
| REM Trying to wake computers | |
| REM The command structure: wolcmd [mac address] [ipaddress] [subnet mask] [port number] | |
| for /f "tokens=1-5 delims=;" %%a in (%_computer_doc%) do echo Waking : %%a && wolcmd %%c %%b %%d %%e >nul && timeout /T 1 /NOBREAK >nul | |
| timeout /t 20 /NOBREAK | |
| goto _ping_status | |
| :_ping_status | |
| REM Run the tasks | |
| REM Pinging the computers to check the status | |
| REM The ping uses the IP if %%b or name if %%a is set in the ping section of the for loops | |
| REM ATTENTION: Its recommeded to have a static IP | |
| color f0 | |
| cls | |
| echo. | |
| echo Status: | |
| echo. | |
| SETLOCAL enabledelayedexpansion | |
| @echo off | |
| FOR /F "tokens=1-5 delims=;" %%a IN (%_computer_doc%) DO FOR /F "tokens=4 delims=(=" %%X IN ('ping -n 2 %%b^|find "loss"') DO ( | |
| set varB=%%X | |
| set varC=!varB: =! | |
| if [!varC!] EQU [0] (echo %%a=OK!) else (echo %%a=Not OK! && echo %%a;%%b >>%_OutputError%) | |
| ) | |
| ENDLOCAL | |
| echo. | |
| start notepad %_OutputError% >nul | |
| pause /t 30 | |
| goto EOF | |
| :EOF | |
| REM Exit the script | |
| cls | |
| exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment