forked from madss/gratisddns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
65 lines (55 loc) · 1.43 KB
/
main.go
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"flag"
"fmt"
"io/ioutil"
"log"
"net/http"
"time"
"runtime"
)
func updateDns(username, password, domain, host string) {
transport := &http.Transport{}
client := &http.Client{Transport: transport}
url := fmt.Sprintf(
"https://ssl.gratisdns.dk/ddns.phtml?u=%s&p=%s&d=%s&h=%s",
username,
password,
domain,
host,
)
log.Printf("Requesting %s\n", url)
res, err := client.Get(url)
if err != nil {
log.Printf("Failed to send request: %q\n", err)
return
}
msg, err := ioutil.ReadAll(res.Body)
res.Body.Close()
if err != nil {
log.Printf("Failed to read response: %q\n", err)
}
log.Printf("Got response: %s\n", msg)
}
func main() {
var username, password, domain, host string
var schedule int
runtime.GOMAXPROCS(1)
log.SetFlags(0)
flag.StringVar(&username, "u", "", "Your gratisdns `username`")
flag.StringVar(&password, "p", "", "Your gratisdns ddns `password`")
flag.StringVar(&domain, "d", "", "Your `domain` (e.g. example.com)")
flag.StringVar(&host, "h", "", "A `host` from your A-records (e.g. www.example.com)")
flag.IntVar(&schedule, "s", 0, "Schedule a dns update every `n` hours")
flag.Parse()
if username == "" || password == "" || domain == "" || host == "" {
flag.PrintDefaults()
return
}
updateDns(username, password, domain, host)
if schedule > 0 {
for _ = range time.Tick(time.Duration(schedule) * time.Hour) {
updateDns(username, password, domain, host)
}
}
}