Skip to content

Instantly share code, notes, and snippets.

@Nithanim
Created April 27, 2019 12:13
Show Gist options
  • Save Nithanim/1c5681da19375e0b2eac24a0ac129192 to your computer and use it in GitHub Desktop.
Save Nithanim/1c5681da19375e0b2eac24a0ac129192 to your computer and use it in GitHub Desktop.
Extremely minimalistic WoL (Wake on Lan/Magic Packet) http webserver
#!/bin/bash
mac_addr=$'\x7B\x01\x2A\xE2\x96\x25'
packet_header=$'\xFF\xFF\xFF\xFF\xFF\xFF'
packet_macs="$mac_addr$mac_addr$mac_addr$mac_addr$mac_addr$mac_addr$mac_addr$mac_addr$mac_addr$mac_addr$mac_addr$mac_addr$mac_addr$mac_addr$mac_addr$mac_addr"
packet="$packet_header$packet_macs"
# Netcat is a bit tricky on some systems e.g debian might not be able to broacast
# or some flags are not available or have a different name
# Used here are no dns lookup (-n), ipv4 (-4), broadcast (-b), udp (-u), shudown after stdin close (-N), don't wait (-w 0)
echo -n "$packet" | nc -n4buNw 0 255.255.255.255 9 && echo "OK" || echo "Error"
#!/bin/bash
while true; do { echo -e 'HTTP/1.0 200 OK\r\n'; bash wol.sh; } | nc -l 8080 -q 1; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment