An example of Python black magic remote control boot

  • 2021-11-01 03:57:21
  • OfStack

Directory

python black magic ~ as long as you know the ip of your computer, remote control can be turned on, hee hee "can only be used for learning ~ no pranks"


def wake_up(request, mac='DC-4A-3E-78-3E-0A'):
    MAC = mac
    BROADCAST = "192.168.0.255"
    if len(MAC) != 17:
        raise ValueError("MAC address should be set as form 'XX-XX-XX-XX-XX-XX'")
    mac_address = MAC.replace("-", '')
    data = ''.join(['FFFFFFFFFFFF', mac_address * 20])  #  Construct the original data format 
    send_data = b''
 
    #  Convert the raw data into 16 Array of binary bytes, 
    for i in range(0, len(data), 2):
        send_data = b''.join([send_data, struct.pack('B', int(data[i: i + 2], 16))])
    print(send_data)
 
    #  Pass socket Broadcast, broadcast at intervals to avoid failure 3 Times 
    try:
        sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
        sock.sendto(send_data, (BROADCAST, 7))
        time.sleep(1)
        sock.sendto(send_data, (BROADCAST, 7))
        time.sleep(1)
        sock.sendto(send_data, (BROADCAST, 7))
        return HttpResponse()
        print("Done")
    except Exception as e:
        return HttpResponse()
        print(e)

Execute the shutdown command


import os
os.system('shutdown -s -t 00')

Related articles: