Created
June 29, 2012 13:57
-
-
Save aharisu/3018095 to your computer and use it in GitHub Desktop.
Wake-on-LANのマジックパケットを投げつけるだけ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use gauche.parseopt) | |
(use gauche.uvector) | |
(use gauche.net) | |
(define (usage) | |
(print "Usage: gosh wol.scm [-m|--mac=<mac-addr>]") | |
(print "Example: gosh wol.scm -m=1a-2b-3c-4d-5e-6f") | |
) | |
(define (main args) | |
(let-args (cdr args) | |
([mac-addr "m|mac=s" => | |
(.$ | |
list->u8vector | |
(pa$ map (cut string->number <> 16)) | |
(cut string-split <> "-"))] | |
[#f "help" => usage] | |
[else (opt . _) (print "Unknown option : " opt) (usage)] | |
. args) | |
(if (and mac-addr (= 6 (u8vector-length mac-addr))) | |
(let ([buf (make-u8vector (* 6 17))] | |
[sock (make-socket AF_INET SOCK_DGRAM)]) | |
(dotimes [i 6] (u8vector-set! buf i 255)) | |
(dotimes [i 16] (u8vector-copy! buf (* (+ i 1) 6) mac-addr)) | |
(socket-setsockopt sock #xffff #x20 1) | |
(socket-sendto sock buf | |
(make <sockaddr-in> :host :broadcast :port 7))) | |
(usage)))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment