[plt-scheme] Wake on Lan in Scheme

From: geb a (geb_a at yahoo.com)
Date: Tue May 1 12:09:01 EDT 2007


The attached file didn't make it into the message...
Here's the code for the wake-on-lan!


(require (lib "pregexp.ss"))

(define port 57111)

(define s (udp-open-socket "" port))

(define MACs (list

;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)
    [(= n 0) ""]
     (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")

(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)))

Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 

Posted on the users mailing list.