Wednesday, September 15, 2010

Remotely wake computers when the network doesn't pass Magic Packets

I'm in a situation where the network we have doesn't pass the UDP 9 magic packet to WoL (wake-on-LAN) remote computers. I'm not sure why this is, but I've developed a solution around it. It requires you to be a domain administrator (or local admin) because it uses PSEXEC and you need to copy a small command-line program to the local machine to execute. To do this in such a way that you can do multiple computers in one pass, you need to create a text file in the same folder as the batch file (upcoming). The text file has the following format:
Note the space between the two. An example:
CAC00700ZZ is off, but it has a MAC address of 00:12:34:56:78
CAC00855FT is on and on the same LAN as CAC00700ZZ. I'm on computer SERVER1 and the link between SERVER1 and CAC00700ZZ doesn't allow the magic packet to traverse. To wake up CAC00700ZZ, I need to send a WoL packet from CAC00855FT. To do this I create a text file called "computer-list.txt" and put in:

CAC00855FT 00:12:34:56:78


Next I need to create a WAKEUP.CMD file and put in the following:
:This script wakes up computers using a tertiary computer on the same LAN.

for /F "tokens=1-2 delims= " %%A IN ('type computer-list.txt') do psexec \\%%A -i -c mc-wol.exe %%B

Lastly, I need to ensure PSEXEC.EXE, MC-WOL.EXE, computer-list.txt and WAKEUP.CMD are in the same folder. MC-WOL.EXE can be downloaded from here. PSEXEC.exe can be downloaded from Microsoft.

If you needed to wake up multiple computers, your computer-list.txt file would look like this:
CAC00700JQ 18A9051BFE68
CAC00700HT 18A9051E2894
CAC00700HQ 18A9051E2B90

No comments: