Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Not wanting to install an OS package to do something as simple as sending some bytes a couple years back, I wrote a shell script to send WoL packets. Its only dependencies are netcat and bash so if you have busybox it should run almost anywhere. It just takes the mac address and interface as an argument and sends a WoL packet on that interface

  #!/bin/bash
  hex="\xFF\xFF\xFF\xFF\xFF\xFF"
  mac_hex="\\x`printf "$1" | sed 's/:/\\\\x/g'`"
  wol_string="$hex"
  for i in {1..16}
  do
      wol_string+="$mac_hex"
  done
  printf "$wol_string" | nc -u -b -w 1 "$2" 9
It took me a while to find an explanation of something so simple, I can't figure out why everyone relies on huge binary packages and libraries to do it. I just needed something on my router so that I could wake my machines from outside the house. I ended up just writing a couple shell scripts that called it and triggering them with nginx via FastCGI so I could click on a link to wake up my machines.


Here's an equivalent shell script that only uses bash builtins, so no other software required:

  #!/bin/bash 
  mac="\\x${1//:/\\x}" 
  wol="\xFF\xFF\xFF\xFF\xFF\xFF" 
  for i in {1..16}; do wol+="$mac"; done 
  printf "$wol" > "/dev/udp/$2/9"




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: