According to the WOL protocol, when the computer is turned off and the NIC is powered, the WOL Magic Packet received from the network will be automatically powered on. This approach can be easily used in environments where remote administration is required. This program realizes the network wake-up Magic packet sending function, can realize the remote boot.
Assume that you need to wake up the PC Nic MAC address is: 01:02:03:04:05:06 the WOL magic Packet structure is as follows:
FF FF FF FF FF | 01 02 03 04 05 06 ... Repeat 16 times ... in Geneva | 00 00 00 00 00 00
6 bytes 0xFF and trailing 6 byte 0x00 without change copy, total packet length: 108 bytes
The PC can be awakened by sending the above packet to the broadcast address of the local subnet (in code: 192.168.1.255) on UDP port 9
Note: This code requires the Python interpreter to run, Windows/linux/mac OS generic
How to use:
1. Save the following code to wol.py
#!/usr/bin/env python#coding=utf-8import socket, sysimport structdef to_hex_int (s): return int (S.upper (), 16) dest = (' 192.168.1.255 ', 9) if len (SYS.ARGV) < 2: print ("Usage: %s <mac address to wakeup> " % sys.argv[0]) sys.exit () mac = sys.argv[1] spliter = "" If mac.count (":") == 5: spliter = ":" If mac.count ("-") == 5: spliter = "-" if spliter == "": print ("mac address Should be like xx:xx:xx:xx:xx:xx / xx-xx-xx-xx-xx-xx ") sys.exit () parts = mac.split (Spliter) a1 = to_hex_int (Parts[0]) a2 = to_hex_int (parts[1]) a3 = to_hex_int (parts[2]) a4 = to_hex_int (parts[3]) a5 = to_hex_int (parts[4]) a6 = to_hex_int (parts[5]) ADDR&NBSP;=&NBSP;[A1,&NBSP;A2,&NBSP;A3,&NBSP;A4,&NBSP;A5,&NBSP;A6]&NBSP;PACKET&NBSP;=&NBSP;CHR (255) &NBSP;+&NBSP;CHR ( 255) &NBSP;+&NBSP;CHR (255) &NBSP;+&NBSP;CHR (255) &NBSP;+&NBSP;CHR (255) &NBSP;+&NBSP;CHR (255) for n In range (0,16): &NBSP;FOR&NBSP;A&NBSP;IN&NBSP;ADDR:&NBSP;&NBSP;PACKET&NBSP;=&NBSP;PACKET&NBSP;+&NBSP;CHR (A ) &NBSP;PACKET&NBSP;=&NBSP;PACKET&NBSP;+&NBSP;CHR (0) + chr (0) + chr (0) + chr (0) &NBSP;+&NBSP;CHR (0) + chr (0) s = socket.socket (socket.af_inet, socket. SOCK_DGRAM) s.setsockopt (socket. Sol_socket,socket. so_broadcast,1) s.sendto (packet,dest) print ("wol packet %d bytes sent !" % len (packet))
2. Use the method for command-line execution (Linux/mac can not need to write commands to start with Python):
Python./wol.py 01:02:03:04:05:06
This article from "IPlay IT" blog, reproduced please contact the author!
Python wol/wakeonlan/Network Wake-up packet sending tool