[plt-scheme] Wake on Lan in Scheme

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

Sorry,

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

Dan

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

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




__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


Posted on the users mailing list.