Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
share|improve this question
    
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 –  harish.venkat 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. –  Gilles Feb 11 '12 at 21:52
    
GNU bash, version 2.05a.0(1)-release (arm-unknown-linux-gnu) –  michelemarcon Feb 13 '12 at 10:43

3 Answers 3

up vote 4 down vote accepted

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 192.0.2.255

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

syslogd -n -O /dev/null -l 0 -R 192.0.2.255/7 &
syslogd_pid=$!
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 192.0.2.255

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/192.0.2.255/7
share|improve this answer
    
My nc doesn't support -u; syslogd doesn't support -l; finally I don't have /dev/udp devices. :( –  michelemarcon Feb 13 '12 at 10:44
    
And yes, I have bash, check my comment above. –  michelemarcon 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). –  Gilles 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.

share|improve this answer

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:

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

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.

share|improve this answer
    
Why the Useless Use of Cat? –  rahmu Sep 11 '13 at 12:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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