Tuesday, May 24, 2011

quick wake on lan script with netcat

An WOL packet is simply the 6 bytes of FF followed by the 6 byte MAC address repeated 16 times.

So to script it first generate the wake packet.. Im assuming the mac is AA:BB:CC:DD:EE:FF and Im storing the packet so I can use it on a machine without xxd..hence the file dump.
ETHER="aa:bb:cc:dd:ee:ff"
ETHER2=`echo $ETHER | sed "s/://g"`
ETHER3="${ETHER2}${ETHER2}${ETHER2}${ETHER2}"
ETHER4="FFFFFFFFFFFF${ETHER3}${ETHER3}${ETHER3}${ETHER3}"
echo ${ETHER4} | xxd -r -p > wake.packet

Then send out the wake packet with Netcat. You can send it directly to the server or to your routers broadcast address it should goto either port 7 or 9. For the example i choose 192.168.1.200 and port 7.
netcat -c -v -u -n -x -p 80 192.168.1.200 7 < wake.packet
The contents of the packet should looks like this:
$ xxd wake.packet
0000000: ffff ffff ffff aabb ccdd eeff aabb ccdd  ................
0000010: eeff aabb ccdd eeff aabb ccdd eeff aabb  ................
0000020: ccdd eeff aabb ccdd eeff aabb ccdd eeff  ................
0000030: aabb ccdd eeff aabb ccdd eeff aabb ccdd  ................
0000040: eeff aabb ccdd eeff aabb ccdd eeff aabb  ................
0000050: ccdd eeff aabb ccdd eeff aabb ccdd eeff  ................
0000060: aabb ccdd eeff                           ......

2 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. thanks for writing this. xxd is a neat toy.

    EDIT - found my question, thanks.

    ReplyDelete