import socket
import struct


def send_packet(mac_str):
    """Send magic packet to given mac address
    :param mac_str: mac address string separated by :
    :return:
    """
    def broadcast(magic):
        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
        s.sendto(magic, ('<broadcast>', 9))

    def build_packet(mac_str):
        bytes = [255] * 6 + [int(x, 16) for x in mac_str.split(':')] * 16
        magic = struct.pack('B' * 102, *bytes)
        return magic

    magic_packet = build_packet(mac_str)
    broadcast(magic_packet)