Skip to content

Instantly share code, notes, and snippets.

@page2me
Forked from SteveMarshall/send-magic-packet.sh
Created January 19, 2020 12:08
Show Gist options
  • Save page2me/2a431f0e265871cf5bdd33c1d2f48ccc to your computer and use it in GitHub Desktop.
Save page2me/2a431f0e265871cf5bdd33c1d2f48ccc to your computer and use it in GitHub Desktop.

Revisions

  1. @SteveMarshall SteveMarshall created this gist Apr 7, 2017.
    21 changes: 21 additions & 0 deletions send-magic-packet.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    #!/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 -w1 -u $broadcast $port