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:
You need something that's capable of sending an Ethernet packet that will be seen by the device you want to wake up.
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 -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
B), and pipe through
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
echo "$wol_packet" >/dev/udp/192.0.2.255/7
/dev/udp is recognized by bash and doesn't really exist in the filesystem, so give it a try.
I think you can use
-l switch, as long as it supports
I have busybox with
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:
bash cat mac2.txt | tr B '\000' >/dev/udp/184.108.40.206/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.