-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.rkt
33 lines (29 loc) · 1.15 KB
/
client.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/racket
#lang racket/base
(require racket/port)
(require racket/tcp)
(require net/url)
(define tcp-port 7265)
(define dns-server "ns1.lutrasoft.com.")
(define key-name "tinytwin.lutrasoft.com.")
(define key-secret-file "secret.key")
(define record-name "tinytwin.lutrasoft.com.")
(define (write-update-request-line port)
(let ([key-secret (call-with-input-file key-secret-file port->string)])
(fprintf port "PUT ~a\r\n"
(url->string
(make-url #f #f #f #f #t
(list (make-path/param record-name '()))
`((key . ,key-name) (secret . ,key-secret))
#f)))))
(define (update-ddns)
(with-handlers ([exn:fail:network? (lambda (e) (format "Unable to connect: ~a" (exn-message e)))]
[exn:fail? (lambda (e) (format "An error occurred: ~a" (exn-message e)))])
(let-values ([(input output) (tcp-connect dns-server tcp-port)])
(write-update-request-line output)
(flush-output output)
(let ([result (port->string input)])
(close-output-port output)
(close-input-port input)
result))))
(display (update-ddns))