Forked from SteveMarshall/send-magic-packet.sh
Last active
September 4, 2022 04:15
-
-
Save imposibrus/b75db3e6a47bf22176713f4f2ed67d5f to your computer and use it in GitHub Desktop.
Wake-On-Lan Magic Packet using netcat in bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
mac_address=$1 | |
# Strip colons from the MAC address | |
mac_address=$(echo $mac_address | sed 's/://g') | |
broadcast=$2 | |
port=9 | |
nc_args="-w1 -u" | |
if [[ $OSTYPE == darwin* ]]; then | |
nc_args="$params -c" | |
fi | |
# 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 -e $magic_packet | nc $nc_args $broadcast $port |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Requirements
If you planning send packet over internet, then open port 9 on your router and forward UDP packets from it to 192.168.1.254 (any unused ip).
Also, you should add static ARP record on router (telnet command for Zyxel Keenetic Start):
After this all packets from internet to UDP/9 port will forward to 192.168.1.254 and acts like broadcast packets.
Usage
send-magic-packet.sh aa:bb:cc:dd:ee:ff 192.168.1.11
Credits