Created
September 18, 2016 03:06
-
-
Save connorjan/136abf1640618ec888ee6259afed1687 to your computer and use it in GitHub Desktop.
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
import socket | |
import struct | |
import argparse | |
import binascii | |
parser = argparse.ArgumentParser(version="0.1",description='Magic packet sender') | |
parser.add_argument('--mac', action="store", default=None, required=True, help="The mac address to wake up") | |
arg = parser.parse_args() | |
arg.mac = arg.mac.replace(":",'') | |
data = ''.join(['FFFFFFFFFFFF', arg.mac * 20]) | |
send_data = '' | |
for i in range(0, len(data), 2): | |
send_data = ''.join([send_data, struct.pack('B', int(data[i: i + 2], 16))]) | |
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) | |
sock.sendto(send_data, ('<broadcast>', 7)) | |
sock.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment