Sunday, April 25, 2010

Wake on LAN command line script

Automate the Wake On LAN (WoL) by scripting a small but smart script.

First, make sure your hosts can wake on LAN, you may have to check the bios but also make sure to enable  wake function from windows, test that it works with the WOL GUI if you'd like and move to the next step when it works.

Second, download the wolcommand from here, I like to place it in C:\WINDOWS\system32 folder so it can be accessed from anywhere in the local system but you can place it in the same folder as the script which makes this command a dependency for the script.

Third step is the scripting portion, as described at the bottom of enable WoL in windows save all the MACs if there are multiple hosts you want to wake up, in my case the list is as follows:
pc00: 00-07-E9-xx-xx-xx
pc01: 00-07-aa-aa-aa-aa
pc02: 00-07-bb-bb-bb-bb

Place as many MACs as needed in this text file, we named it ip-mac.txt but you can name it anything else and have any other delimiter but make sure to edit the script below accordingly if you do have changes.

Now the fun part:
FOR /F "tokens=2 delims=:" %%G IN (ip-mac.txt) DO wolcmd %%G 192.168.1.255 255.255.255.255
pause

Named it wol.bat (or anything you like) and run or schedule with at command or  The first line is a FOR loop that takes the second field with colon delimiter (:) then execute "wolcmd " with each of the MAC address lines, it may help to learn more about FOR loops to understand this for your case.

Second line is a pause which will wait for user input any key, I just want to make sure the commands were successful otherwise the command window closes before you blink.

Anyway, this seems to work with most PCs, I am also considering placing a sleep few seconds between each MAC wake execution to give the packets time to leave before sending the next.

Let me know what you think!

Enable Wake On LAN Windows XP

In order to wake the computer from the Local Area Network you may need to check the BIOS to allow this but since there are too many different ones I will cover the Windows XP enabling (same with server 2003 and similar to older and newer versions of windows operating systems).
On your PCs Network Interface Cards (NICs) you require to "Allow this device to bring the computer out of standby", and here is how to do it:

1. First locate the Local Area Network properties, normally can be found in Control Panel > Network Connections (Fig. 1) double-click your network connection to get to the Status
Fig. 1
2. Next in Status click Properties:
Fig. 2
3. Now in the Properties click Configure:
Fig. 3
4. Now click the "Power Management" tab and select the check-boxes with the wake on LAN capabilities.
Fig. 4
Since with the Intel drivers this section looks different for me, here is a more common look for this tab:
Fig. 5
You will need to check the bottom two boxes and click OK until there are no more open.
And this will -in theory- allow you to bring the computer from a turned off or standby/hibernate state to a powered on and running state.

There are various ways of doing this: Make sure to record the MAC Address found in Support > Details of Fig. 2
Fig. 6 
Press Ctrl+c to copy these details and past them into a noetpad text file and save it for future references.

Next, there are many routers that have the capability to wake the computer's by MAC, either by default firmware or upgraded, in any case I prefer the software on a server in the LAN, so the while the rest of the computers sleep the server can be scheduled to wake them up via the WOL software which can be scripted in my next post.