Skip to content

Instantly share code, notes, and snippets.

@valvallow
Forked from aharisu/wol.scm
Created June 30, 2012 00:15
Show Gist options
  • Save valvallow/3021540 to your computer and use it in GitHub Desktop.
Save valvallow/3021540 to your computer and use it in GitHub Desktop.
Wake-on-LANのマジックパケットを投げつけるだけ
#!/bin/sh
ssh -i /home/valvallow/.ssh/kaisha/id_rsa valvallow@kaisha-no-server '~/wol-srv.sh'
#!/bin/sh
/home/valvallow/wol 1a 2b 3c 4d 5e 6f
#!/usr/local/bin/gosh
(use gauche.uvector)
(use gauche.net)
(define (usage)
(print "usage: wol <mac address>")
(print "example: wol 1a 2b 3c 4d 5e 6f")
(exit 1))
(define (main args)
(when (or (null? (cdr args))
(not (= 6 (length (cdr args)))))
(usage))
(let1 mac-addr (list->u8vector
(map (cut string->number <> 16)
(cdr args)))
(print (cdr args))
(print 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))
(print "done"))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment