Skip to content

Instantly share code, notes, and snippets.

@BriungRi
Created February 16, 2023 20:20
Show Gist options
  • Save BriungRi/d36566d82037e093110ba9ec593aabd9 to your computer and use it in GitHub Desktop.
Save BriungRi/d36566d82037e093110ba9ec593aabd9 to your computer and use it in GitHub Desktop.
Script to send a magic packet to your Windows machine
#!/usr/bin/env python3
import socket
import sys
import codecs
if len(sys.argv) < 3:
print("Usage: wakeonlan.py <ADR> <MAC> (example: 192.168.1.255 00:11:22:33:44:55)")
sys.exit(1)
mac = sys.argv[2]
data = ''.join(['FF' * 6, mac.replace(':', '') * 16])
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
decode_hex = codecs.getdecoder("hex_codec")
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
sock.sendto(decode_hex(data)[0], (sys.argv[1], 9))
@BriungRi
Copy link
Author

Make sure port 9 is open on the target machine to wake!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment