;WOL is based on the following principle: ;When the PC shuts down, the NIC still gets power, and keeps listening on the network for a 'magic' packet to arrive. This packet must contain a certain byte-sequence, but can be encapsulated in any kind of packet (IPX, IP, anything). ;This program uses UDP for sending the packet. The complete UDP packet, sent over an ethernet interface, looks something like this: ;[ethernet header][IP header][UDP header][Magic sequence][CRCS] ;The only goal of the script is to send this packet over the network. It expects no returning data, since the NIC only listens, and does not reply anything. ;The Magic Packet is a broadcast frame, transmitted over port 7 or 9. It can be sent over a variety of connectionless protocols (UDP, IPX) but UDP is most commonly used. The data that is contained in a Magic Packet is the defined constant as represented in hexadecimal: FF FF FF FF FF FF followed by sixteen (I've also seen six) repetitions of the target computer's MAC address, possibly followed by a four or six byte password. (require (lib "pregexp.ss")) (define port 57111) (define s (udp-open-socket "127.0.0.1" port)) (define MACs (list "" "00:13:72:A2:A6:76" "00:13:72:A2:B0:96" "00:13:72:A2:A9:5B" "00:13:72:A2:A9:33" "00:13:72:A2:A8:EE" "00:13:72:A2:A8:BE" "00:13:72:A2:A9:01" "00:13:72:A2:9F:6E" "00:13:72:A2:A8:5E" "00:13:72:A2:B2:84" "00:13:72:A2:95:91" "00:13:72:A2:CC:DC" "00:13:72:A2:A9:0B" "00:13:72:A2:CB:D1" "00:13:72:A2:9A:31" "00:13:72:A2:A9:38" "00:13:72:A2:A8:CF" "00:13:72:87:C6:AE" "00:13:72:87:0F:D0" "00:13:72:87:A9:3F")) ;string->bytes : string(representing a mac address) -> byte string of the same (define (string->bytes mac) (apply bytes-append (map string->bytes/utf-8 (pregexp-split ":" mac)))) ;(string->bytes "00:13:72:A2:A6:76") #"001372A2A676" ;repeat: string (mac address) -> string (with repetition n times) (define (repeat mac n) (cond [(= n 0) ""] [else (string-append mac (repeat mac (sub1 n)))])) ;magic-packet: string (mac address) -> bytes (define (magic-packet mac) (let ((mac (string->bytes (repeat mac 16)))) (bytes-append (string->bytes/utf-8 "FFFFFFFFFFFF") mac))) (define (wol-packet from to) (bytes-append (string->bytes to) (string->bytes from) (string->bytes/utf-8 "0842") ;packet type is 0x0842 (magic-packet to))) (udp-send-to s "pc03" port (wol-packet (list-ref MACs 11)(list-ref MACs 3))) (udp-send-to s "pc03" port (wol-packet (list-ref MACs 11)(list-ref MACs 3))) (udp-send-to s "pc03" port (wol-packet (list-ref MACs 11)(list-ref MACs 3))) (udp-send-to s "pc03" port (wol-packet (list-ref MACs 11)(list-ref MACs 3))) (udp-send-to s "pc03" port (wol-packet (list-ref MACs 11)(list-ref MACs 3)))