Skip to content

Instantly share code, notes, and snippets.

@Lomanic
Forked from SteveMarshall/send-magic-packet.sh
Last active June 21, 2019 17:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lomanic/090ce11c881de215c6a72199ada51f67 to your computer and use it in GitHub Desktop.
Save Lomanic/090ce11c881de215c6a72199ada51f67 to your computer and use it in GitHub Desktop.
Wake-On-Lan Magic Packet using netcat in bash
#!/usr/bin/env bash
mac_address=$1
# Strip colons from the MAC address
mac_address=$(echo $mac_address | sed 's/://g')
broadcast=$2
port=4343
# Magic packets consist of 12*`f` followed by 16 repetitions of the MAC address
magic_packet=$(
printf 'f%.0s' {1..12}
printf "$mac_address%.0s" {1..16}
)
# ... and they need to be hex-escaped
magic_packet=$(
echo $magic_packet | sed -e 's/../\\x&/g'
)
# echo $magic_packet
echo -e $magic_packet | nc -b -w1 -u $broadcast $port
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment