Is it possible to implement the wake-on-lan magic packet in bash? I'm using a old, customized BusyBox and don't have ether-wake. Is it possible to replace it with some other shell command, like:

wakeonlan 11:22:33:44:55:66
  • wakeonlan, although it seems to require perl which probably isn't in your busybox.
    – jw013
    Feb 10 '12 at 15:36
  • if you are able to use python see code.activestate.com/recipes/358449-wake-on-lan and put alias for this in your .bashrc Feb 10 '12 at 19:38
  • Since BusyBox has a lot of configuration options, you should tell us what you have. Also, are you sure that you have bash? Bash and BusyBox is an extremely unusual combination. Feb 11 '12 at 21:52
  • GNU bash, version 2.05a.0(1)-release (arm-unknown-linux-gnu) Feb 13 '12 at 10:43

You need something that's capable of sending an Ethernet packet that will be seen by the device you want to wake up.

The ether-wake command in BusyBox is exactly what you're after. If your BusyBox doesn't have it, consider recompiling BusyBox to include it.

If you have a sufficiently “bloaty” netcat (BusyBox can have one of two nc implementations, one of which handles TCP only), you can send a manually crafted UDP packet to the broadcast address of the network segment that the device is connected to.

mac=$(printf '\xed\xcb\xa9\x87\x65\x43') # MAC = ed:cb:a9:87:65:43
wol_packet=$(printf "\xff\xff\xff\xff\xff\xff$mac$mac$mac$mac$mac$mac$mac$mac$mac$mac$mac$mac$mac$mac$mac$mac")
echo "$wol_packet" | nc -u 7

Another BusyBox utility that you could abuse into sending that packet is syslogd.

syslogd -n -O /dev/null -l 0 -R &
logger "$wol_packet"
kill $!

If the MAC contains a null byte, you won't be able to craft the packet so easily. Pick a byte that's not \xff and that's not in the MAC, say \x42 (B), and pipe through tr.

echo "$wol_packet" | tr B '\000' | nc -u 7

If you really have bash (which is extremely unusual on devices with BusyBox — are you sure you really have bash, and not another shell provided by BusyBox?), it can send UDP packets by redirecting to /dev/udp/$hostname/$port.

echo "$wol_packet" >/dev/udp/
  • My nc doesn't support -u; syslogd doesn't support -l; finally I don't have /dev/udp devices. :( Feb 13 '12 at 10:44
  • And yes, I have bash, check my comment above. Feb 13 '12 at 10:45
  • @michelemarcon Your strange device seems to lack the fundamental component of every method I can think of. I recommend compiling and uploading a binary (a more complete BusyBox, for example). Feb 14 '12 at 6:47

/dev/udp is recognized by bash and doesn't really exist in the filesystem, so give it a try.

I think you can use syslogd without -l switch, as long as it supports -R.

I have busybox with syslogd withount -R, no nc nor bash and I'm still stuck.


I have an ssh server running on old HTC dream. My version of busybox also didn't include ether-wake and I'm not skilled enough to compile my own busybox. Fortunately I managed to wake up my PC using:

cat mac2.txt | tr B '\000' >/dev/udp/

Notice that the broadcast ip is different in my network.

I crafted the file (mac2.txt) containing the magic packet on my PC and pushed it to the server via SFTP. Because my mac has null byte I have to use tr to substitute all x42 bytes with 00. It worked like charm.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.